One prisoner was not seen by a doctor after collapsing and complaining of shortness of breath; she died that day of heart failure. A second woman’s rapid weight gain and severe chest pain were ignored until her heart also failed. For a third, it was sudden weight loss, wheezing and back pain; she was found dead during her dialysis, after a nurse left her unattended. A fourth died at a hospital; her neurological disorder went undiagnosed until she had a stroke.

All four were inmates at Fluvanna Correctional Center for Women. A federal judge ruled Wednesday that the state prison in central Virginia is failing to provide adequate medical care and must make immediate changes to end what amounts to cruel and unusual punishment.

“Over six years ago, women at FCCW filed this lawsuit, seeking a remedy for pervasive constitutionally deficient medical care,” Judge Norman K. Moon wrote. “Their quest continues. Some women have died along the way.”

His ruling comes soon after a Justice Department investigation concluded a Portsmouth, Va., jail also was failing inmates and probably violating the Constitution.

The Fluvanna suit was brought by the Legal Aid Justice Center, whose attorney Shannon Ellis said in a statement that the “opinion flatly rejects the state’s attempts to point the finger elsewhere and confirms that the state has only itself to blame for the tragic state of healthcare at FCCW.”

Moon approved a settlement agreement between Fluvanna and a group of prisoners in 2016, requiring substantial reforms and an independent compliance monitor. But three years later, Moon wrote, the prison is continuing to flout the law.

There are still few too nurses, he found, who often fail to follow through on required work. Vaccines are not given; test results are not relayed. Even emergency transportation arrives when needed little more than half of the time.

Twice when an inmate was dying, oxygen was unavailable — though the second death occurred just days after the first, when the need was made fatally clear.

After one woman’s cellmate found her bleeding from the mouth and unresponsive and called for help, “two nurses came casually walking in,” with no medical equipment, and had to wait for a stretcher to arrive from across the prison campus, the judge wrote, drawing on testimony from a one-week trial in June.

Failures extend beyond the deaths, Moon found. Medical records are spotty. Medication ran out because nurses did not reorder it, a problem they would hide by claiming inmates simply didn’t show up for their doses. Prisoners who complained that they were sick were routinely ignored.

One inmate did not get a recommended colonoscopy for three years and ultimately was diagnosed with rectal cancer that already had spread to her liver. A nurse had diagnosed her with hemorrhoids. Another overdosed on anti-seizure medication given to her by the prison medical staff; her complaints of feeling disoriented were ignored until she blacked out. A few months later a nurse gave her three times the proper dose of another medication, putting her in the infirmary.

Officials for the prison argued that they were trying to comply with the settlement but were unequipped to do so. Nurses are in high demand nationally and do not want to work in corrections, they said, particularly at a prison with a bad reputation.

“We do not know what the answers are. Sometimes when you are in the middle of a crisis, you do not know what you need to get out of it,” Warden Jeff Dillman wrote to Virginia Department of Corrections leadership in 2017.

Moon dismissed those arguments, saying compliance required actual changes, not just a desire to change. His injunction requires the prison to staff more nurses and properly train them; put stretchers, oxygen and a suction machine in every housing building; develop a new protocol for timely medical care and review any future deaths for failures.

“The Settlement Agreement does not set an Olympic bar for Defendants. It does not require FCCW to be the Mayo Clinic or Johns Hopkins Hospital,” he wrote. “Instead, the Settlement Agreement simply imposes very basic medical standards and tasks that will bring medical care to an adequate level, something that has been and continues to be absent in significant respects.”

In a statement, a spokeswoman for the Virginia Department of Corrections said the judge’s ruling “clarifies some of the provisions of the settlement agreement” and that the department “has continued to work to provide appropriate medical care to inmates.”

An earlier version of this article incorrectly attributed a letter about conditions in Fluvanna Correctional Center for Women to Warden Eric Aldridge. The letter was written by his predecessor, Jeff Dillman.