New York’s infamous Rikers prison complex will close by 2027, earlier than originally planned, under an agreement reached Wednesday between Mayor Bill de Blasio and city council leaders.

The deal came just hours after the state Commission of Correction released a report that said New York state may have to intervene in the shutdown of the sprawling penitentiary if the city didn’t improve the situation at the island prison.

Rikers Island, located in the East River between Queens and the Bronx, houses about 9,000 inmates. It continues to be plagued by failures in management and regulatory compliance, according to the commission’s report.

The agency said it has tried to help jail management fix the issues, but the ongoing problems highlight “the need for closure of all jail facilities located on Rikers Island.”

The deal announced Wednesday calls for moving 5,000 Rikers inmates to smaller jails around the city.

The plan called for opening or expanding jails in Manhattan, Brooklyn, Queens and the Bronx to replace Rikers.

The four sites together will house about 5,000 inmates.

De Blasio said the new system will create a “safer and fairer” borough-based jail system.

While the plan to close Rikers is backed by the state, Gov. Andrew Cuomo’s administration is not pleased with the timeline— it wants faster action.

“If the governor and the legislature want to help us close Rikers more quickly, they have the power to do so,” de Blasio said Wednesday. “And if they don’t, then it’s on them that it’s going to take longer.”