The District is running one of its most controversial landlords out of town.

After years of racking up housing code violations and lawsuits alleging deplorable conditions, Sanford Capital reached a settlement with the D.C. attorney general’s office last month that requires it to sell off its remaining seven properties and stay out of subsidized housing for the next seven years.

Since 2006, Sanford has received millions in taxpayer dollars through housing vouchers and affordable housing tax credits as it built a network of at least 20 complexes with more than 1,300 units.

District officials continued doing business with Sanford — even after repeatedly suing the company for poor housing conditions — because they said Sanford was among the few companies willing to rent to the city’s poorest.

“There was some fear that D.C. residents were reliant on Sanford, and Sanford can’t leave,” said Attorney General Karl A. Racine (D) in an interview. “But I think it’s clear now that landlords, developers and owners like Sanford cannot act with impunity, and if they do, they will be called to account. . . . And now there’s a threat that they’ll even be escorted out of the District of Columbia.”

Aubrey Carter Nowell, who launched Sanford Capital with Patrick B. Strauss, did not return a request for comment.

Critics said they took advantage of an affordable housing crisis in a rapidly gentrifying city.

Dozens of people living in Sanford apartments in the poorest parts of the city have complained about lack of heat in winter, vermin infestation and sewage backing up into units. Many tenants feared the landlord allowed the buildings to deteriorate to drive out residents, redevelop the units and rent them at market rates. But faced with few affordable alternatives, some tenants stayed.

Tenant advocates hailed the settlement to shutter Sanford’s operations but questioned whether the city has done enough to prevent similar situations.

“I’m glad that they are being driven out. That’s definitely going to lead to better outcomes for the tenants,” said Rob Wohl, an organizer with the Latino Economic Development Center who worked with tenants in a Sanford building.

“But the actual enforcement mechanisms have not changed,” he said. “Nothing has been done to actually create the economic incentives to comply with the law here. I’m skeptical this big case the attorney general did is going to disincentivize other companies from doing the same thing.”

After The Washington Post and Washington City Paper published news reports last year about the plight of Sanford tenants, Mayor Muriel E. Bowser (D) ordered the Department of Consumer and Regulatory Affairs to inspect all Sanford buildings. Until then, repeated violations and fines had not triggered additional scrutiny of Sanford’s buildings, so Bowser directed the DCRA to develop a system that flags properties with a problematic history and takes a more proactive approach to enforcement of the building code.

A spokesman for the DCRA said it has collected $158,000 of $277,000 in fines levied against Sanford.

Will Merrifield, an attorney with the Washington Legal Clinic for the Homeless, said other companies will pursue similar strategies as long as the city relies on temporary vouchers to prevent homelessness.

“Unless the city figures out how to right this market and really create quality, safe affordable housing, I think there will be people living in that market that Sanford exploits,” Merrifield said.

“Companies like Sanford Capital are just sitting there waiting to gobble up those subsidies and make a lot more money than they would be able to make otherwise renting out units in decrepit conditions,” he said.

It’s unclear how Sanford’s bottom line has been affected by the city’s enforcement efforts.

Property records show that Sanford unloaded at least 12 of 20 complexes in its portfolio, some sold in foreclosure or bankruptcy and others sold for millions more than the purchase price.

Sanford still owns seven apartment complexes in Southeast Washington, according to the attorney general’s office, while another is tied up in litigation.

Under the settlement with the attorney general, Novo Management, which already manages hundreds of units in the Washington region, would take over day-to-day management and maintenance at any buildings Sanford hasn’t sold after six months. Sanford would still own the properties and would have to file monthly reports with the attorney general’s office detailing its efforts to sell them.

Additionally, Sanford cannot buy new buildings where rents are publicly subsidized through tax credits or where a certain number of tenants are using government vouchers until 2025.

Sanford declared bankruptcy regarding at least two complexes and sold them for more than the debt they claimed for the properties. This also enabled the company to bypass the city’s Tenant Opportunity to Purchase Act, which would have required Sanford to give the tenants the chance to buy the buildings before selling them to a third party.

“What Sanford has illustrated is you file for bankruptcy and bankruptcy court approves the sales, and you don’t have to worry about the tenants,” said Beth Harrison, an attorney for the Legal Aid Society of the District of Columbia, which is representing Sanford tenants in the two bankruptcy sales. “It’s an end run.”

D.C. Council member Anita Bonds (D-At Large), who chairs the housing committee, is sponsoring legislation that would preserve the right of first refusal for tenants during bankruptcy.

“I hope other bad actors that may be out there may take heed and know we just can’t tolerate abuse, particularly when you are collecting dollars from the government and from individuals to perform a service and don’t deliver,” Bonds said. “We want to stop the bad actions when they are occurring, as opposed to having people live in misery long-term.”