It shall be a defense to an action for summary process that such action or the preceding action of terminating the tenant's tenancy, was taken against the tenant for the tenant's act of commencing, proceeding with, or obtaining relief in any judicial or administrative action the purpose of which action was to obtain damages under or otherwise enforce, any federal, state or local law, regulation, by-law, or ordinance, which has as its objective the regulation of residential premises, or exercising rights pursuant to section one hundred and twenty-four D of chapter one hundred and sixty-four, or reporting a violation or suspected violation of law as provided in section eighteen of chapter one hundred and eighty-six, or organizing or joining a tenants' union or similar organization or making, or expressing an intention to make, a payment of rent to an organization of unit owners pursuant to paragraph (c) of section six of chapter one hundred and 83A, or a tenant, co-tenant or a member of the household taking action under section 3 of chapter 209A or section 3 of chapter 258E, seeking relief under sections 23 to 29, inclusive, of chapter 186, reporting to any police officer or law enforcement professional an incident of domestic violence, rape, sexual assault or stalking, as defined in said section 23 of said chapter 186, against a tenant, co-tenant or member of the household, or reporting to any police officer or law enforcement professional a violation of an order issued under said section 3 of said chapter 209A or said section 3 of said chapter 258E or any act of abuse as defined in section 1 of said chapter 209A or any act of harassment as defined in chapter 258E directed against the tenant, co-tenant or member of the household. The commencement of such action against a tenant, or the sending of a notice to quit upon which the summary process action is based, or the sending of a notice, or performing any act, the purpose of which is to materially alter the terms of the tenancy, within six months after the tenant has commenced, proceeded with or obtained relief in such action, exercised such rights, made such report, organized or joined such tenants' union, or made or expressed an intention to make a payment of rent to an organization of unit owners, or within six months after any other person has taken such action or actions on behalf of the tenant or relating to the building in which such tenant resides, shall create a rebuttable presumption that such summary process action is a reprisal against the tenant for engaging in such activities or was taken in the belief that the tenant had engaged in such activities. Such presumption may be rebutted only by clear and convincing evidence that such action was not a reprisal against the tenant and that the plaintiff had sufficient independent justification for taking such action, and would have in fact taken such action, in the same manner and at the same time the action was taken, even if the tenant had not commenced any legal action, made such report or engaged in such activity.
Mass. Gen. Laws ch. 239, § 2A