A privatised prison marred by riots, drugs, suicides, violence and “appalling” conditions has been taken back under permanent government control.

Officials denied the unprecedented move was a “public versus private sector issue”, but critics claimed years of warnings over outsourcing prisons had been vindicated.

Mark Fairhurst, chairman of the Professional Trades Union for Prison, Correctional and Secure Psychiatric Workers (POA), said: “The obsession this Tory government has to outsource and privatise public sector work must cease.

“It is obvious that when you put profits above safety you sow the seeds of disorder, mismanagement, cover ups and misery.”

UK prison conditions: in pictures Show all 8 1 /8 UK prison conditions: in pictures UK prison conditions: in pictures A cell covered in graffiti at HMP Liverpool. PA UK prison conditions: in pictures HMP Liverpool has some of the worst conditions inspectors have seen. HM Inspectorate of Prisons/PA UK prison conditions: in pictures A broken window in a cell at HMP Liverpool HM Inspectorate of Prisons/PA Wire UK prison conditions: in pictures A shower unit with protruding electric cable at HMP Liverpool HM Inspectorate of Prisons/PA UK prison conditions: in pictures Litter at HMP Liverpool HM Inspectorate of Prisons/PA Wire UK prison conditions: in pictures A wall damaged by damp at HMP Liverpool HM Inspectorate of Prisons/PA UK prison conditions: in pictures A pool table at HMP Liverpool HM Inspectorate of Prisons/PA UK prison conditions: in pictures A sign for HMP Liverpool, where drones are seized at a rate of more than one a week. The prisons watchdog flagged up the impact of the remote-controlled flying devices at HMP Liverpool. PA

HMP Birmingham was privatised in 2011, with a 15-year contract being awarded to G4S, which also runs four other prisons.

In an “urgent notification” issued in August, HM chief inspector of prisons, Peter Clarke, hit out at an “abject failure of contract management and delivery” after finding some inmates too frightened to leave their cells, while others openly smoked drugs.

In the wake of a 15-hour riot in 2016 involving hundreds of prisoners, MrClarke said HMP Birmingham had “slipped into a state of crisis” and was under “tenuous” control.

He warned of rising violence and self-harm amid “appalling” living conditions, seeing blood and vomit left on floors in wings infested with cockroaches and rats.

HM Prison and Probation Service (HMPPS) took temporary control for an initial six-month period following the alert, which was extended in February.

A spokesperson said it “has now decided, with the full agreement of G4S, to end the contract and bring HMP Birmingham back in-house”.

Rory Stewart, the prisons minister, said progress had been made since the government stepped in but continuity was needed.

“That is why we have mutually agreed with G4S that the public sector is better placed to drive the long-term improvements required and the contract will end,” he added.

Prisons minister Rory Stewart admits government shouldn't have cut officer numbers

“Our priority remains the safety of prisoners and staff but this move to restore and consolidate order at one of our most challenging jails will ultimately make sure that we are better protecting the public.”

The Ministry of Justice said contraband searches had increased and that more senior management and experienced officers had been brought in, alongside new safety initiatives, refurbishment and training.

Richard Burgon, Labour’s shadow justice secretary, said: “Labour has repeatedly warned that the Tories’ ideological obsession with running prisons for private profit is dangerously flawed.

“This is a necessary decision but falls well short of what is needed. The government must show that it has learnt the lessons and immediately abandon plans for yet more privately run prisons.”

Mr Fairhurst also called on the government to ensure all new prisons remain in the public sector, but Mr Stewart said it still supported “a mixed economy of providers”, adding that some private jails were “among the best performing in the country”.

“Indeed, G4S itself is running excellent prisons at Altcourse and Oakwood, and this government believes passionately that private providers should continue to play a crucial role in our system,” he added.

Mr Stewart has vowed to resign if conditions at 10 selected prisons, not including Birmingham, do not improve – sparking accusations that resources have been diverted.

G4S will pay £9.9m towards the cost of the government running HMP Birmingham since August, and its staff are being transferred to HMPPS contracts on 1 July under governor Paul Newton.

The company’s managing director for custodial and detention services, Jerry Petherick, said the jail had faced “exceptional challenges” including high violence.

Support free-thinking journalism and attend Independent events

“We believe that it is in the best interests of staff and the company that management of this prison is transferred to HMPPS and we will work closely with the Ministry of Justice to ensure a smooth transition over the next three months,” he added.

“We will continue to deliver high quality services at the other four major UK prisons that we manage.”

It follows a series of scandals for G4S, including abuse at immigration detention centres, GPS tagging failures, a “humiliating shambles” over security at the 2012 London Olympics and a restraint death.