The U.S. Department of Justice and the state of Alabama on Monday agreed to settle a long-running lawsuit alleging that the state's prisons are unconstitutionally filthy, unsafe and violent.

The proposed settlement of the 2020 lawsuit was announced hours before the start of a bench trial in which several inmates were expected to testify about conditions behind bars. The trial had been expected to last at least six weeks, with nearly 900 witnesses.

If approved by U.S. District Judge Harold D. Mooty III, who scheduled a hearing in the case for Tuesday, the settlement would require the state to take concrete steps to improve its lockups. The proposed agreement spells out steps the state should take, including assigning correctional staff to each housing unit, conducting hourly unannounced checks and maintaining records on inmate-on-inmate assaults.

Alabama Attorney General Steve Marshall said the state is under a court-enforceable order to maintain prison infrastructure, recruit and retain correctional officers, prevent violence, stop the flow of contraband and prosecute crimes committed in prison by inmates and staff. The settlement sets out a three-phase process: a rewrite of prison policy, training for staff, and compliance checks by the Justice Department. Policy changes in the first phase must be finalized no later than six months after the settlement is approved by the court.

The agreement does not require an outside monitor to verify compliance, and it prohibits the Justice Department from seeking federal control of the system or a court-ordered release of prisoners.

The case made news when it was first filed in 2020 as the first time the Justice Department's Civil Rights Division had sued a state over statewide prison conditions. A years-long investigation found severe overcrowding and understaffing in prisons where deaths were not accurately reported, sexual abuse was highly prevalent and prisoners had access to dangerous weapons, according to a Justice Department report released in 2019.

U.S. Attorney Phillip Williams for the Northern District of Alabama credited Marshall and Attorney General-elect Katherine Robertson with helping negotiate a settlement only hours before the trial was supposed to begin. "This lawsuit was filed against Alabama six years ago this month and a great deal of progress has been made by the Department of Corrections in that time," Williams said.