It seems like landlords have all the power in these situations and can make completely arbitrary and unfair decisions to rip off the tenants.
There is no cheap and easy way to avoid being ripped off but there are a few points that can be made:
No 1 is to protect yourself by documenting everything to do with the tenancy from inception, paying particular attention to rental payment trails, utility bills (and meter readings), maintenance expenses you or the landlord have paid.
Also the inventory of fixtures and furnishings is vital - make sure it is thoroughly checked at the outset and you notify the agent or landlord of any deficiencies or errors. Check and agree everything at the end.
When you leave the property do the rounds with the landlord or agent and discuss any claimed shortcomings at that point rather than wait for a dispute later on when you have no access to the property to prove the state you left it in. Videoing the property might be an idea.
If you still end up in dispute with the landlord after all this then it must simply be a try on on their part. A formal letter setting out your claim and threatening legal action can work wonders. If you suspect that the landlord is not declaring the rent for tax this is another point of leverage you can use.
If you have to resort to a lawyer a simple letter from a lawyer costs around 75-100€ from Advoco. (http://www.advoco.es/services.html)
Forum discussion of bad deposit experiences: http://www.myspain.es/forum/legal-financial/18308-problem-non-return-deposit-flat-rental.html
Related articles:http://hubpages.com/hub/How-to-rent-out-your-Spanish-property-online