The person entitled to the premises may recover possession by eviction when:
(1) any person holds over real property:
(i) after a sale of the property on an execution or judgment; or
(ii) after the expiration of the time for redemption on foreclosure of a mortgage, or after termination of contract to convey the property, provided that if the person holding the real property after the expiration of the time for redemption or termination was a tenant during the redemption or termination period under a lease of any duration and the lease began after the date the mortgage or contract for deed was executed but prior to the expiration of the time for redemption or termination, and the person has received:
(A) at least two months' written notice to vacate no sooner than one month after the expiration of the time for redemption or termination, provided that the tenant pays the rent and abides by all terms of the lease; or
(B) at least two months' written notice to vacate no later than the date of the expiration of the time for redemption or termination, which notice shall also state that the sender will hold the tenant harmless for breaching the lease by vacating the premises if the mortgage is redeemed or the contract is reinstated;
(2) any person holds over real property after termination of the time for which it is demised or leased to that person or to the persons under whom that person holds possession, contrary to the conditions or covenants of the lease or agreement under which that person holds, or after any rent becomes due according to the terms of such lease or agreement; or
(3) any tenant at will holds over after the termination of the tenancy by notice to quit.
It is a defense to an action for recovery of premises following the alleged termination of a tenancy by notice to quit for the defendant to prove by a fair preponderance of the evidence that:
(1) the alleged termination was intended in whole or part as a penalty for the defendant's good faith attempt to secure or enforce rights under a lease or contract, oral or written, under the laws of the state or any of its governmental subdivisions, or of the United States; or
(2) the alleged termination was intended in whole or part as a penalty for the defendant's good faith report to a governmental authority of the plaintiff's violation of a health, safety, housing, or building code or ordinance.
If the notice to quit was served within 90 days of the date of an act of the tenant coming within the terms of clause (1) or (2) the burden of proving that the notice to quit was not served in whole or part for a retaliatory purpose shall rest with the plaintiff.
In any proceeding for the recovery of premises upon the ground of nonpayment of rent, it is a defense if the tenant establishes by a preponderance of the evidence that the plaintiff increased the tenant's rent or decreased the services as a penalty in whole or part for any lawful act of the tenant as described in subdivision 2, providing that the tenant tender to the court or to the plaintiff the amount of rent due and payable under the tenant's original obligation.
Nothing contained in subdivisions 2 and 3 limits the right of the landlord pursuant to the provisions of subdivision 1 to terminate a tenancy for a violation by the tenant of a lawful, material provision of a lease or contract, whether written or oral, or to hold the tenant liable for damage to the premises caused by the tenant or a person acting under the tenant's direction or control.
(a) An action for recovery of the premises may combine the allegation of nonpayment of rent and the allegation of material violation of the lease, which shall be heard as alternative grounds.
(b) In cases where rent is outstanding, a tenant is not required to pay into court the amount of rent in arrears, interest, and costs as required under section 504B.291 to defend against an allegation by the landlord that the tenant has committed a material violation of the lease.
(c) If the landlord does not prevail in proving material violation of the lease, and the landlord has also alleged that rent is due, the tenant shall be permitted to present defenses to the court that the rent is not owing. The tenant shall be given up to seven days of additional time to pay any rent determined by the court to be due. The court may order the tenant to pay rent and any costs determined to be due directly to the landlord or to be deposited with the court.