Yes, it is possible (although rare) for a tenant to win an unlawful detainer action and as a consequence, be permitted to stay. As long as the tenant can prove that the landlord agreed to a rent credit, it does not matter whether the repairs were general maintenance repairs or something more substantial.
It would also depend on how much back rent we are talking about. If the back rent is equal to the amount of the work credit, then the facts are definitely arguable - and you should see an attorney immediately.
If the back rent owed is greater than the rent credit, then you will probably not be able to remain in possession.