
21 So.3d 883 (2009)
QUALITY ROOF SERVICES, INC., Appellant,
v.
INTERVEST NATIONAL BANK, Appellee.
No. 4D08-3382.
District Court of Appeal of Florida, Fourth District.
October 28, 2009.
*884 Virginia Cassady, Clifford B. Shepard and Morgan G. Bourdat of Shepard, Smith & Cassady, P.A., Maitland, for appellant.
Diane Noller Wells of Devine Goodman Pallot Rasco & Wells, P.A., Coral Gables, Joshua Magidson and Nancy S. Paikoff of MacFarlane Ferguson & McMullen, Clearwater, for appellee.
PER CURIAM.
The appellant, Quality Roof Services, Inc. ("Quality Roof"), appeals the trial court's order denying Quality Roof's Amended Motion to Amend Answer to Plaintiff's Complaint and the resulting Order Granting Motion For Final Summary Judgment, For Entry of Final Judgment of Foreclosure of Apartment Complex and For Award of Attorneys' Fees and Costs, and the award of Partial Summary Judgment of Foreclosure of Apartment Complex. This court has jurisdiction. Fla. R.App. P. 9.030(b)(1)(A).
This appeal arises from a foreclosure action filed by Intervest against The Villas at Lauderhill, LLC, the owner of an uninhabitable, hurricane-damaged apartment complex ("the Villas"). Quality Roof is a roofing contractor that subcontracted to furnish materials, labor, and equipment for roofing, stucco, and other hurricane repairs for the Villas. Intervest is the lender which refinanced the Villas' pre-existing mortgage indebtedness. Intervest filed a first mortgage on the property and recorded on August 19, 2005. Quality Roof recorded a claim of lien against the Villas for unpaid invoices on July 25, 2007.
Intervest filed its foreclosure action on November 29, 2007. Quality Roof was joined as a defendant because of its recorded claim of lien. Quality Roof did not raise any affirmative defenses, nor did it cross-claim to enforce or foreclose its claim of lien. The Villas at Lauderhill, LLC, consented to final summary judgment and the sale of the property, and Intervest moved for final summary judgment on June 11, 2008. The hearing on the motion was scheduled for July 17, 2008. Quality Roof did not file any affidavits or other evidence in contravention of Intervest's summary judgment motion and supporting affidavits.
On July 3, 2008, Quality Roof moved to amend its answer and assert an affirmative defense of unclean hands against Intervest to prevent Intervest's foreclosure. Responding on July 14, 2008, Intervest claimed that the amendment would be futile and prejudicial. On July 16, 2008, the day before the hearing, Quality Roof served an amended motion to amend its answer, which elaborated its allegations of Intervest's unclean hands. In the amended motion to amend, Quality Roof alleged that Intervest failed to properly distribute insurance proceeds it had received from a hurricane damage insurance claim on the Villas; and but for Intervest's wrongful actions, the default would not have occurred and the property would not have been foreclosed upon.
On July 17, 2008, the trial court held a hearing on both Quality Roof's Motion to Amend and Intervest's motion for final summary judgment. In denying the Motion to Amend, the trial judge found that *885 although allowing the amendment would not prejudice Intervest, the amendment would be futile in the context of the case as currently postured. We agree that Intervest would not be prejudiced, but disagree that allowing the amendment would be futile. We therefore reverse and remand.
A trial court's denial of a motion to amend is reviewed for abuse of discretion. See Noble v. Martin Mem'l Hosp. Ass'n, 710 So.2d 567, 568 (Fla. 4th DCA 1997). Florida Rule of Civil Procedure 1.190(e) states that "[a]t any time in furtherance of justice, upon such terms as may be just, the court may permit any process, proceeding, pleading, or record to be amended or material supplemental matter to be set forth in an amended or supplemental pleading." A court "should be especially liberal when leave to amend is sought at or before a hearing on a motion for summary judgment." Thompson v. Bank of New York, 862 So.2d 768, 770 (Fla. 4th DCA 2003) (citation omitted); see also Montero v. Compugraphic Corp., 531 So.2d 1034, 1036 (Fla. 3d DCA 1988). In ruling on a motion for leave to amend, "all doubts should be resolved in favor of allowing an amendment, and the refusal to do so generally constitutes an abuse of discretion unless it clearly appears that allowing the amendment would prejudice the opposing party, the privilege to amend has been abused, or amendment would be futile." Cason v. Fla. Parole Comm'n, 819 So.2d 1012, 1013 (Fla. 1st DCA 2002); see also Fields v. Klein, 946 So.2d 119, 121 (Fla. 4th DCA 2007); Thompson, 862 So.2d at 770. A proposed amendment is futile if it is insufficiently pled, id., or is "insufficient as a matter of law," Burger King Corp. v. Weaver, 169 F.3d 1310, 1320 (11th Cir.1999).
Although the unclean hands defense may be asserted in foreclosure cases when the parties are in privity, see, e.g., Knight Energy Servs., Inc. v. Amoco Oil Co., 660 So.2d 786, 789 (Fla. 4th DCA 1995); Lamb v. Pike, 659 So.2d 1385, 1387 (Fla. 3d DCA 1995), privity is not an essential element of the equitable defense. Unclean hands may be asserted by a defendant who claims that the plaintiff acted toward a third party with unclean hands with respect to the matter in litigation. See Yost v. Rieve Enters., Inc., 461 So.2d 178 (Fla. 1st DCA 1984) ("There is no bar to applying the doctrine of unclean hands to a case in which both the plaintiff and the defendant are parties to a fraudulent transaction perpetrated on a third party."); see also Hauer v. Thum, 67 So.2d 643, 645 (Fla.1953) ("It would matter not that the [defendants] were parties to the fraudulent transaction nor that the fraud was perpetrated upon a third party."); Marin v. Seven of Five Ltd., 921 So.2d 699, 700 (Fla. 4th DCA 2006) ("Generally, the conduct constituting the unclean hands must be connected with the matter in litigation.") (citation omitted).
Here, the trial court should have allowed Quality Roof to assert its affirmative defense of unclean hands. The affirmative defense was sufficiently pled and, as a matter of law, is sufficient to be able to prevent a foreclosure. Based on Quality Roof's allegations that the default and foreclosure would not have occurred but for Intervest's unclean hands, Quality Roof need not be in privity with Intervest to assert its affirmative defense. We note, however, that unclean hands may not be used in this case to subordinate Intervest's mortgage to Quality Roof's lien. Indeed, at oral argument, counsel for Quality Roof conceded that Quality Roof did not seek to have its lien become superior to Intervest's mortgage. Therefore, on remand, the trial *886 court should allow Quality Roof to assert its affirmative defense of unclean hands.
Reversed and remanded.
POLEN, STEVENSON and GERBER, JJ., concur.
