
206 Cal.App.3d 438 (1988)
253 Cal. Rptr. 609
CLAYTON DEVELOPMENT COMPANY, INC., Plaintiff and Appellant,
v.
MICHAEL P. FALVEY et al., Defendants and Respondents.
Docket No. D006901.
Court of Appeals of California, Fourth District, Division One.
December 6, 1988.
*441 COUNSEL
Diane E. Douglas Tufts for Plaintiff and Appellant.
Dorazio, Barnhorst & Bonar and Joel L. Incorvaia for Defendants and Respondents.
OPINION
KREMER, P.J.
Plaintiff Clayton Development Company, Inc. (Clayton), appeals summary judgment favoring defendants Michael and Christie Falvey (Falvey) on its action on a promissory note. Clayton contends the court erred in holding the action was barred by California antideficiency *442 statutes. Clayton also attacks the attorney fee award favoring Falvey. We affirm.

I
For purposes of Falvey's motion for summary judgment the parties stipulated:
In 1981 Falvey decided to buy a condominium as an investment from Ascot Park Associates (Ascot), a partnership in which Clayton was a partner. Ascot's agent Krikorian said Falvey's total investment would be "10% down" of the $105,000 total sales price and that Ascot would give Falvey "a second for 15% of the sales price" at 12 percent interest for three years with no payments due the first year.
Falvey was substituted as buyer in an existing escrow. To close the escrow, Falvey received a $78,750 loan from Pacific Federal Savings and Loan Association (Pacific Federal) and executed a note secured by a first trust deed in favor of Pacific Federal on the condominium.
Clayton and Krikorian arranged the transaction so Ascot would receive a second trust deed through a second escrow. Clayton believed the arrangement would circumvent the antideficiency statutes. Falvey was not aware of Clayton's intent to avoid the antideficiency statutes.
The second escrow opened June 25, 1981, for preparation of documents giving Ascot its second deed of trust on the property. In that escrow Falvey executed a $15,750 note favoring Ascot (the second note). In the note Falvey agreed to pay attorney fees if an action was instituted on the note. Falvey also executed a second trust deed to secure repayment of the note. However, because Krikorian gave the escrow company an incorrect legal description the second trust deed actually encumbered a condominium unit other than Falvey's. Clayton and Falvey did not know of the mistake. Later the second note and second trust deed were assigned to Clayton.
In June 1982 Falvey defaulted on the Pacific Federal note. In July 1982 Falvey defaulted on the second note. In January 1983 Pacific Federal recorded notice of default against the property. In February 1983 Ascot discovered the encumbrance error on the second trust deed. Krikorian asked Falvey to execute a new trust deed containing the correct legal description. Falvey did not do so.

II
In April 1983 Clayton sued Falvey on the second note. In August 1983 Pacific Federal foreclosed on the property. On August 12, 1983, two days *443 after Pacific Federal sold the property at foreclosure, Falvey answered Clayton's complaint, asserting Code of Civil Procedure[1] sections 726 and 580b as affirmative defenses. Falvey cross-complained against Clayton, seeking reformation of the trust deed, rescission, and declaratory relief.[2]
In November 1985 the case went to nonbinding judicial arbitration, where Falvey prevailed against Clayton's complaint. Clayton then requested a trial de novo, but a courtroom shortage prevented prompt assignment to a trial department. To avoid a substantial delay before trial, the parties agreed to submit the issues raised by Clayton's complaint on a motion for summary judgment by Falvey based on stipulated facts. In the motion Falvey contended the second trust deed's mistaken legal description created an equitable mortgage favoring Clayton with the result that direct action on the second note was barred under section 726's one-action rule and section 580b's antideficiency provisions.
The superior court granted summary judgment favoring Falvey. The court also awarded Falvey attorney fees. Clayton appeals.

III
Clayton attacks the summary judgment as contrary to law. (1a) Clayton contends it was entitled to sue on the underlying note obligation without first seeking to foreclose on a security interest because no legal mortgage existed given the erroneous property description and no equitable mortgage had been declared by any court at the time Clayton sued on the second note. We disagree.
Civil Code section 2922 provides: "A mortgage can be created, renewed, or extended, only by writing, executed with the formalities required in the case of a grant of real property." (2) However, `"[d]espite the formalities required by section 2922, it is settled that "[e]very express executory agreement in writing, whereby the contracting party sufficiently indicates an intention to make some particular property, real or personal, or fund, therein described or identified, a security for a debt or other obligation ... creates an equitable lien upon the property so indicated, which is enforceable against the property in the hands not only of the original contractor, but of his ... purchasers or encumbrancers with notice." [Citation.] Thus, a promise to give a mortgage or a trust deed on particular property as security for a debt will be specifically enforced by granting an equitable mortgage. [Citations.] An agreement that particular property is security for *444 a debt also gives rise to an equitable mortgage even though it does not constitute a legal mortgage. [Citations.] If a mortgage or trust deed is defectively executed, for example, an equitable mortgage will be recognized. [Citations.] Specific mention of a security interest is unnecessary if it otherwise appears that the parties intended to create such an interest. [Citations.]' [Citation.]" (Kaiser Industries Corp. v. Taylor (1971) 17 Cal. App.3d 346, 350-351 [94 Cal. Rptr. 773], quoting Coast Bank v. Minderhout (1964) 61 Cal.2d 311, 313-314 [38 Cal. Rptr. 505, 392 P.2d 265].)
(1b) Clearly the parties intended their deal to be a secured transaction. Indeed, Clayton concedes "[t]he debt was to have been secured by a 2nd trust deed on real property sold to Defendants by Plaintiff." Falvey executed a trust deed intended and believed by all parties to encumber the property purchased. The trust deed's description of the property was faulty. However, given the parties' undisputed intent, the erroneous trust deed constituted a security interest in the property and an equitable mortgage was created. (Kaiser Industries Corp. v. Taylor, supra, 17 Cal. App.3d at pp. 350-353.)[3]
Section 580b prohibits a deficiency judgment "after any sale of real property ... under a deed of trust, or mortgage, given to the vendor to secure payment of the balance of the purchase price of real property...." (3) Even where the security has been exhausted by a senior lienor's sale under a first trust deed, section 580b's antideficiency provision precludes recovery of a deficiency judgment by the junior lienor who has taken a purchase money trust deed. (Brown v. Jensen (1953) 41 Cal.2d 193, 197-198 [259 P.2d 425].) Clayton concedes the second note "evidenced a `purchase money' obligation." Having concluded the parties intended a secured purchase money transaction and an equitable mortgage was created, we hold it follows that Clayton's suit on the second note is barred by section 580b. (Cf. Kaiser Industries Corp. v. Taylor, supra, 17 Cal. App.3d at p. 352.)
(4) Although we are unaware of any cases discussing the applicability of section 580b to transactions involving equitable mortgages, we find applying *445 the statute here to be appropriate. Equitable mortgages have been held to constitute security interests in real property for purposes of section 726.[4] In Kaiser Industries Corp. v. Taylor, supra, 17 Cal. App.3d at page 352, after concluding the parties intended a secured transaction and an equitable mortgage was created, the court stated the creditor was required to follow the procedure specified in section 726, that is, foreclose on that security. The court rejected the creditor's contention he could elect his remedy and either sue first to establish an equitable lien and to foreclose it or sue on the underlying obligation. The court stated: "If there is in fact an equitable mortgage, the choice of which remedy to pursue is not open to the creditor." (Id. at p. 353.)
Sections 580b and 726 are part of a statutory scheme protecting defaulting borrowers from being disadvantaged by lenders. (Bank of America v. Daily (1984) 152 Cal. App.3d 767, 772 [199 Cal. Rptr. 557].) Indeed, section 726 specifically refers to section 580b. Both statutes should be read as applying to equitable, as well as legal, mortgages. The reasons for including equitable mortgages within the scope of section 726 are equally compelling with respect to section 580b. An equitable mortgage is a form of security interest. (Kaiser Industries Corp. v. Taylor, supra, 17 Cal. App.3d at p. 353.) If in fact an equitable mortgage exists, the creditor has no choice of remedy. (Ibid.) Construing section 580b as not embracing equitable mortgages would undermine the purpose of the antideficiency statutes by permitting the creditor an election between either enforcing an equitable lien and being treated as a secured creditor or circumventing the antideficiency statutes and suing on the underlying note if such better suited the creditor's needs. Such construction here would result in Clayton receiving an unmerited windfall simply because Clayton's predecessor's agent fortuitously misdescribed the property to be encumbered. Accordingly, we hold section 580b bars a deficiency judgment where, as here, an equitable mortgage exists securing payment of the balance of a real property purchase money note favoring the vendor.

IV
In light of our holding section 580b precludes Clayton's action on the note, we need not decide the extent of section 726's application to the facts here. (5) Generally when the parties intend a secured transaction and an equitable mortgage is created, the creditor is required to follow the procedure specified in section 726 and foreclose on that security. (Kaiser Industries *446 Corp. v. Taylor, supra, 17 Cal. App.3d at p. 352.) Where the debtor successfully raises section 726 as an affirmative defense, the creditor must exhaust the security before he may obtain a money judgment against the debtor for any deficiency. (Walker v. Community Bank (1974) 10 Cal.3d 729, 734 [111 Cal. Rptr. 897, 518 P.2d 329].) However, where the security has been exhausted or rendered valueless through no fault of the creditor, the creditor may bring action on the debt "... on the theory that the limitation to the single action of foreclosure refers to the time the action is brought rather than when the trust deed was made, and that if the security is lost or has become valueless at the time the action is commenced, the debt is no longer secured. [Citations.]" (Brown v. Jensen, supra, 41 Cal.2d at pp. 195-196.) Here the security became valueless only after Clayton commenced its action on the note. Whether under these circumstances section 726 might not be an obstacle to Clayton's proceeding with its action on the note through supplemental pleading or otherwise is a question we need not address because such action would in any event be barred by section 580b.
The superior court correctly held Clayton was not entitled to recover on the note. Summary judgment favoring Falvey was proper.

V
In February 1987 when Falvey's cross-complaint was still pending, the superior court signed an order granting Falvey's motion for summary judgment on Clayton's complaint and awarding Falvey attorney fees in defending against the complaint. Later the court determined the attorney fee award was premature. Falvey then dismissed the cross-complaint and again sought attorney fees. In June 1987 the court awarded Falvey $16,122.81 attorney fees.
Clayton contends the court erred in awarding Falvey attorney fees, asserting the court lacked jurisdiction, Falvey's right to attorney fees never matured, and the amount awarded was excessive. Clayton's contentions are without merit.
(6) Clayton asserts the court lacked jurisdiction to award attorney fees while Falvey's cross-complaint was pending. However, the court did not determine the amount of the fee award until after Falvey dismissed the cross-complaint. At such time the court could properly determine Falvey was the prevailing party entitled to fees.
(7) Clayton also asserts Falvey's entitlement to attorney fees never matured because sections 726 and 580b rendered unenforceable Clayton's right to damages for breach of contract. Supporting its contention, Clayton relies *447 on Geffen v. Moss (1975) 53 Cal. App.3d 215 [125 Cal. Rptr. 687, 79 A.L.R.3d 1232], where the court found a contract to be unenforceable as a matter of public policy, rendering any contractual attorney fee provision also unenforceable. Clayton's reliance on Geffen is misplaced. In Geffen, the court voided a contract for the sale of a law practice as contrary to public policy. Unlike the contract in Geffen, the parties' underlying contract here was not void. Clayton's action on the contract was simply defeated because Falvey successfully asserted the affirmative defenses of sections 726 and 580b. Falvey was entitled to attorney fees for such successful defense by reason of the note's provisions and Civil Code section 1717.[5] (Care Constr., Inc. v. Century Convalescent Centers, Inc. (1976) 54 Cal. App.3d 701, 707 [126 Cal. Rptr. 761]; see also Winnett v. Roberts (1986) 179 Cal. App.3d 909, 923 [225 Cal. Rptr. 82].)
(8a) Finally, Clayton attacks as excessive the award of $16,122.81 attorney fees. (9) The amount of attorney fees to be awarded is within the sound discretion of the trial court. (Bruckman v. Parliament Escrow Corp. (1987) 190 Cal. App.3d 1051, 1062 [235 Cal. Rptr. 813]; Schoolcraft v. Ross (1978) 81 Cal. App.3d 75, 82 [146 Cal. Rptr. 57].) In determining the reasonableness of attorney fees requested, the court should consider "... `the nature of the litigation, its difficulty, the amount involved, the skill required and the skill employed in handling the litigation, the attention given, the success of the attorney's efforts, his learning, his age, and his experience in the particular type of work demanded [citation]; the intricacies and importance of the litigation, the labor and the necessity for skilled legal training and ability in trying the cause, and the time consumed.'" (Clejan v. Reisman (1970) 5 Cal. App.3d 224, 241 [84 Cal. Rptr. 897]; quoting Berry v. Chaplin (1946) 74 Cal. App.2d 669, 679 [169 P.2d 453].) (8b) Considering those factors, we find the amount awarded by the court below was within its discretion. Although the amount may appear high in light of the amount sought in Clayton's complaint, the award was not unreasonable. (See Bruckman v. Parliament Escrow Corp., supra, 190 Cal. App.3d 1051, affirming a $16,022.25 attorney fee award on a judgment for $8,297.01 plus $3,216.21 interest.) The case involved complicated issues, extensive pretrial discovery and numerous hearings. Falvey's counsel's defense of the action included conducting extensive research about the antideficiency statutes, preparing an answer to Clayton's complaint including affirmative defenses, preparing and serving interrogatories, requests for production of documents *448 and requests for admissions, attending Falvey's deposition, taking the depositions of Krikorian, Clayton's principal and the escrow manager, preparing a brief and stipulated statement of facts for arbitration, appearing at two settlement conferences, filing a settlement conference brief, preparing for trial, appearing twice for trial when courtrooms proved unavailable, and preparing a motion for summary judgment with a stipulated statement of facts. In defending the action Falvey's counsel's office spent 607 hours of attorney, paralegal and legal assistant time at hourly rates from $40 to $160. Falvey submitted voluminous billing statements supporting the attorney fee request. On this record the court acted within its discretion in awarding Falvey $16,122.18 attorney fees.

DISPOSITION
The judgment is affirmed. Falvey is entitled to attorney fees on appeal in an amount to be determined by the superior court upon filing of a cost bill.
Todd, J., and Staniforth, J.,[*] concurred.
NOTES
[1]  All statutory references are to the Code of Civil Procedure unless otherwise specified.
[2]  Eventually Falvey dismissed the cross-complaint.
[3]  Kish v. Bay Counties Title Guaranty Co. (1967) 254 Cal. App.2d 725 [62 Cal. Rptr. 494], relied upon by Clayton, is factually distinguishable. Kish did not involve an equitable mortgage. In Kish the parties' intentions the debt be secured never matured into fact because the debtor never executed any security device. (Id. at p. 731.) Falvey, on the other hand, executed a second trust deed intended and believed by all parties to encumber the property purchased.

Also unavailing is Clayton's reliance on Christopherson v. Allen (1961) 190 Cal. App.2d 848 [12 Cal. Rptr. 658]. Christopherson did not involve an equitable mortgage. Christopherson simply held unsecured notes are not embraced by section 580b. The court stated section 580b "by its terms refers only to security transactions, that is, where the seller is secured for the payment of the purchase price by the property sold." (Id. at p. 851.)
[4]  Section 726 provides: "There can be but one form of action for the recovery of any debt or the enforcement of any right secured by mortgage upon real property, which action must be in accordance with the provisions of this chapter." The referenced chapter provides for the remedy of foreclosure by judicial sale.
[5]  Civil Code section 1717, subdivision (a), provides in relevant part: "In any action on a contract, where the contract specifically provides that attorney's fees and costs, which are incurred to enforce that contract, shall be awarded either to one of the parties or to the prevailing party, then the party who is determined to be the party prevailing on the contract, whether he or she is the party specified in the contract or not, shall be entitled to reasonable attorney's fees in addition to other costs."
[*]   Retired Associate Justice of the Court of Appeal sitting under assignment by the Chairperson of the Judicial Council.
