Some details are missing, most critically when you were to pay him the agreed upon amount. Sounds like he is suing for failure to return the deposit within 30 days as required by law (although he could also be claiming other violations of the security deposit law). However, if you agreed with him to a compromise on its return because there were legitimate reasons to hold the security deposit, then by all means bring that agreement to the judge's attention. If the judge finds that agreement to be binding, you should be OK. But again, when under that agreement were you to pay him the compromise amount? If you two did not agree on that point, there is a risk to you.
1) Have you fully returned it?
2) Did the tenant file the complaint before or after you returned it?
Under the relevant statute (186 s15B) you have to return the full deposit within 30 days unless you follow very precise procedures to keep it. Most landlords get the procedure wrong, so even if they try to do the right thing they end up breaking the law.
I have rarely seen a judge award triple damages when the deposit was returned prior to the filing of a complaint, even if the return time was after the 30 day period. But once the complaint is filed, in most cases the landlord can no longer avoid the triple damages.
This is an interesting situation. You're saying that you have some sort of agreement which would extend the time. I'm actually not sure such an agreement would even be permissible under 186 s15B (and what would the consideration be for the agreement?) But in any case you'll need to bring the agreement to an attorney.
Do you want accurate, personalized, legal advice that you can rely on? You will have to hire an attorney, not ask on Avvo. I am not your attorney and am not creating an attorney-client relationship by this post. I am therefore giving only general advice. This advice may not apply to you or your situation; may not take account of all possibilities, and may not match the advice I would give to a client. DO NOT rely on this advice or any other advice on Avvo to make your legal decisions. If you want an answer to a legal question you should retain an attorney who is licensed in your state.
You need to speak with an experience Landlord/Tenant attorney. Oftentimes clerks will not listen to reason in this situation. You would also need to provide further details about the "agreement." Was it memorialized somehow?