In 1985, when the District was still warehousing juvenile offenders in a pair of decrepit, vermin-infested detention centers — each rife with violence and lacking any meaningful health care or rehabilitation programs — a group of lawyers filed a 42-page complaint in D.C. Superior Court, demanding reforms.

“The plaintiffs live under conditions that are inhumane and that inflict needless suffering,” the attorneys wrote.

Today, 35 years and seven mayoral administrations later, the court case that began with those words is the oldest active lawsuit against the D.C. government, spanning generations of lawyers and judges. The stacks of pleadings and rulings in the file, the volumes of reports and transcripts, offer a reminder of what the District was three decades ago: a broken city ravaged by social ills and mired in fiscal dysfunction.

The atrocious system of youth detention back then seemed to be just another of the District’s myriad hopeless problems.

Finally, the end could be near for the tortuous litigation, dubbed “the Jerry M. case” for one of its many plaintiffs, all of whom were incarcerated juveniles in the 1980s. A judge gave preliminary approval Wednesday to a proposed settlement of the case after advocates for reform said the city, reborn economically in the 21st century, is at last treating young offenders properly.

“There really have been solid, astounding gains,” said Elizabeth Alexander, a co-counsel for the plaintiffs since 2001. After the hearing at which Judge Herbert B. Dixon Jr. gave an initial thumbs-up to the planned settlement, Alexander, who specializes in inmate rights litigation, said of the current detention system: “Not everything is wonderful, of course. But overall, it’s been an amazing transformation.”

In fact, lawyers said, the system is widely viewed as a national model.

Clinton Lacey, who became director of the D.C. Department of Youth Rehabilitation Services in 2015, called the winding-down of the Jerry M. case “a major milestone for the District.” Standing in a courthouse hallway with about two dozen lawyers and city officials after the hearing, Lacey said, “We’ve reached the point where we all agree that we are at a high level now, and that’s something we can be proud of.”

The old facilities, the Oak Hill Youth Center and the Cedar Knoll Youth Center, both in Laurel, Md., have been replaced by the secure, yet less prisonlike, New Beginnings Youth Development Center, where offenders receive a greater range of services in a cleaner, safer environment, lawyers said.

About 40 detainees live at New Beginnings, which is also in Laurel. The facility has 60 beds. In 1985, Oak Hill and Cedar Knoll were chronically overcrowded, often housing 200-plus juveniles combined.

Lawyers said the reduced population reflects another achievement of the lawsuit: Early in the litigation, the city agreed to abandon a lock-’em-up approach to juvenile justice and adopt a more progressive philosophy, emphasizing community-based rehabilitation programs to reduce the number of youths in confinement. Lacey also said the number of juveniles arrested in the District each year has gone down significantly over time.

The system today “is almost unrecognizable” compared with even 15 years ago, said the plaintiffs’ lead attorney, Alan Pemberton, who joined the case in 2004. Before New Beginnings opened in 2009, “you had very young children housed alongside kids who were much older, and it was a very dangerous situation,” he said. Now “they’re running that facility successfully at below capacity, which is a huge accomplishment.”

Staff members at New Beginnings also are better trained than their overworked predecessors at Oak Hill and Cedar Knoll, Pemberton said.

If Dixon (the third judge to preside over the case since 1985) gives final approval to the proposed resolution later this year, the city would create an oversight agency to monitor further improvements in the system, mainly involving medical and mental health care. With the new agency taking over the court’s long-standing role of ordering and supervising changes, lawyers said, the Jerry M. litigation would be closed.

“The settlement agreement is a tremendous victory for our local autonomy,” Mayor Muriel E. Bowser (D) said in a statement.

In the 35 years since the case began, the District has changed enormously.

Newcomers to today’s thriving, gentrified District would scarcely recognize the decaying, crime-ridden Washington of decades ago. Middle-class flight, a shriveled tax base, municipal mismanagement and an impoverished population needing budget-busting social services left the District on the brink of bankruptcy as the millennium approached.

The lawsuit, naming then-Mayor Marion Barry (D) as a defendant, described Cedar Knoll as “an antiquated ‘reform school’ whose buildings have become unfit for habitation and whose programs are grossly limited and wholly inadequate. The children live in buildings that are insufficiently heated and ventilated, are infested with vermin, and have gaping holes in walls and ceilings.”

Oak Hill, also falling apart and crawling with vermin, was likewise devoid of effective mental health services and educational and vocational classes for learning-disabled youngsters, according to the complaint. Like Cedar Knoll, Oak Hill was permeated by “a climate of violence” in which ill-trained, overworked employees “periodically assault the children who are in their care,” the lawsuit said.

The class-action case was filed on behalf of eight youths listed only by their first names and last initials, starting with Jerry M., as well as “all others” housed in Oak Hill and Cedar Knoll, where illicit drug use and fights among detainees were commonplace. The plaintiffs have never been fully identified publicly; those still living are middle-aged.

In 1986, reform advocates and city officials signed a consent decree, filed in court, in which the District promised to correct a litany of problems at the two facilities and develop community-based programs as alternatives to detention. With the D.C. government virtually broke in the 1990s, scant progress was made.

“In May 1993, after accumulating more than $2 million in fines at $1,000 per day for each youth over capacity, the District finally closed Cedar Knoll,” according to a history of the litigation published by nonprofit groups involved in the reform efforts. As a result of the closure, overcrowding at Oak Hill grew even worse.

Meanwhile, in 1995, with the city’s finances in disarray, Congress created an independent control board to oversee the D.C. budget. It took six years for the board to restore fiscal stability. After local elected officials resumed the reins of government in 2001 and focused on growing the tax base, new development policies led to rapid gentrification and the economic vitality that continues in the city today.

Only then, in the new century, did the reforms envisioned in the Jerry M. consent decree begin to gain traction, including programs to reduce youth incarceration.

The District’s Omnibus Juvenile Justice Act of 2004 abolished the D.C. Youth Services Administration, the agency in charge of juvenile detention. Youth Services, which had been part of the city’s Department of Health, was replaced by the new cabinet-level Department of Youth Rehabilitation Services, with more authority and funding.

The 2004 bill also mandated the closing of Oak Hill within five years. In 2009, the facility was shuttered and New Beginnings opened.

Outside Dixon’s courtroom Wednesday, Pemberton, the plaintiffs’ lawyer, called the hearing “a watershed moment” for reform advocates and for the city.

“There are some things remaining to be done with medical and mental health” care for detainees, Pemberton said. Then he gestured to Lacey, the youth rehabilitation director, standing nearby in the crowd. “But if there’s something critical to be taken care of, we don’t think they’ll need the court’s supervision anymore.”