When Bob Rogerson went hunting for an apartment close to the Shakespeare Theatre Company where he would be attending a one-year graduate program, a rental agent showed him a property near H Street that was right in his price range.

The agent assured him that the apartment’s problems ­— including paint varnish peeling off the bedroom floors and broken stair balustrades — would be repaired before the Rogerson family moved in.

“When we got there on our move-in date, none of it had been done,” Rogerson says. The stove didn’t even work.

He and his wife, Christine, were most concerned for the safety of their 1-year-old daughter who might have eaten the peeling paint while crawling around.

“It was a poisonous place for a kid to be,” he says.

The Rogersons could have been seriously stuck, but thanks to Washington, D.C., laws aimed at protecting renters, they were able to get out of their new lease in just one week.

With 60 percent of Washing-tonians renting, the District offers strong tenant protections. Nearby counties in Virginia and Maryland are less renter-friendly, but some areas — such as Montgomery County — are working to change that.

Rogerson says his independent landlord was initially reluctant to let the family out of the lease they’d signed. But the company that managed the apartment on the landlord’s behalf, John C. Formant Real Estate, helped the Rogersons show the landlord that the law was on the tenants’ side in this case.

Joel Cohn, legislative director for the D.C. Office of the Tenant Advocate, says there’s “an implied warranty of habitability implicit in every lease” — meaning that if your home is not livable, you can “move out without penalty.”

If you find yourself in an unlivable apartment in the District, the first thing to do is contact the D.C. Department of Consumer and Regulatory Affairs (1100 4th St. SW, 202-442-4400) and request an apartment inspection. Then bring the report from that inspection to D.C.’s Office of the Tenant Advocate (2000 14 St. NW, 202-719-6560) for help.

No matter what, D.C. tenants should not withhold rent while settling their issue, Cohn says.

If you absolutely refuse to give money to your landlord, put the monthly rent you would be paying into an escrow account until the dispute is resolved.

If you encounter a similar problem outside of the District, it might be more difficult to rectify.

“In Virginia, it certainly would be harder to get out of a lease than in the District,” says Fairfax-based attorney Ed Goss.

Each county in Virginia, as well as in Maryland, has different policies, so Goss recommends that you contact your local tenant advocate office if you think your landlord is not fulfilling his responsibilities. Most counties require you to try to fix the problem with the landlord directly, so you should immediately notify your landlord in writing of your concerns.

Things get a little bit trickier if you need to get out of your lease for some other reason — such as moving out of town or getting married.

You’re off the hook if someone else rents your place. In theory, the landlord should help. If the broken lease dispute were ever to find its way to court, most judges would expect landlords to “proactively seek to replace the tenant,” Cohn says.

Of course, you can also try to find your own replacement. When the rental market is hot, the odds are in your favor, but it’s not a guarantee. And the new renter still needs to win the landlord’s approval.

Matt Losak is the executive director of Renters Alliance, a tenant advocacy organization that was formed in 2011 in Montgomery County in Maryland. He says that in these situations “it’s in both parties’ interest to work to a solution.”

He recommends that you communicate with your landlord as soon as possible if you know you will be moving away.

During their dispute, the Rogersons found an ally in their management company, Formant, which helped the family get out of the unlivable apartment and into another one of its homes, a two-bedroom in Lincoln Park. Even though it was listed for more money, Formant only charged them their original rent amount.

“Our management company has a heart of gold,” Rogerson says, and because of it, a story about a housing nightmare got a happy ending.