BRASÍLIA — Brazilian President Dilma Rousseff swore in predecessor Luiz Inácio Lula da Silva as her new cabinet chief Thursday, but a judge quickly quashed the appointment amid allegations she was trying to protect him from corruption charges.

Rousseff attacked her enemies for trying to remove her in a “coup” as she sealed her risky bet to team up again with her old mentor, whose new position grants him ministerial immunity, protecting him from prosecution in criminal court.

She got as far as giving Lula a post-ceremony hug before federal judge Itagiba Catta Preta suspended the embattled ex-president’s nomination to the cabinet chief post “or any other that grants him immunity.”

The preliminary injunction, which must still be reviewed by a higher court, can be appealed.

It plunges Rousseff’s tottering government into even deeper uncertainty as the president fights off new impeachment proceedings, mass protests, a deep recession and the splintering of her coalition.

Lula and Rousseff, the leftist leaders who have governed Brazil for the past 13 years, were all sharp suits and warm smiles at the swearing-in ceremony at the presidential palace, belying the catastrophic political and economic crises gripping the once-booming Latin American giant.

But the ceremony reignited the protests sparked Wednesday by an anti-corruption judge’s leak of a damning wire-tapped phone call between Rousseff and Lula suggesting she appointed him to save him from arrest.

“Shame!” shouted a protester as Lula was sworn in. The ex-president’s supporters for their part chanted slogans accusing their opponents of seeking a coup.

“The putschists’ shouting won’t make me veer from my path or bring us to our knees,” said Rousseff.

Wiretap

Lula, the once wildly popular president who led Brazil from 2003 to 2011, is charged with accepting a luxury apartment and a country home as bribes from executives implicated in a multi-billion-dollar corruption scam at state oil company Petrobras.

Rousseff vehemently denies she appointed him to help him dodge prosecution, insisting she needs his political acumen to help rescue her government from crisis.

Rousseff called Lula’s bugged phone to tell him she would be sending him the official decree nominating him as her chief of staff so he could make use of it “if necessary.”

That extract seems to confirm that Lula’s nomination was aimed at saving him from possible arrest.

Cabinet ministers can only be tried before the Supreme Court in Brazil, and ministerial immunity would protect Lula from criminal court.

Lula denies involvement in the scandal, in which investigators say construction companies conspired with Petrobras executives to overbill the oil giant to the tune of $2 billion, paying huge bribes to politicians and parties along the way.

The president’s office said the phone call was about a simple procedural matter and accused Moro of a “flagrant violation of the law and the constitution.”

Beginning of the end?

The recording caused thousands of people to flood into the streets to protest in cities including the capital Brasilia and the largest city São Paulo.

Some three million Brazilians also protested Sunday in nationwide demos calling for Rousseff’s departure.

Rousseff faced a new battle in the legislature Thursday, as the lower house prepared to launch a committee to consider impeaching her over accusations she manipulated government accounts to boost public spending during her 2014 re-election campaign.

A first impeachment attempt last year stalled over procedural issues.

Lula, the 70-year-old co-founder of the ruling Workers’ Party (PT), left office with 80 percent popularity ratings and the status of a hero to the left.

During his two terms, he presided over a watershed period of prosperity and social programs that helped lift tens of millions out of poverty.

But his legacy is threatened not only by the money-laundering charges he faces, but also by the perception among many Brazilians that his entire administration was underpinned by graft.

Rousseff, 68, chaired Petrobras during much of the period under investigation, but so far faces no charges.

The São Paulo stock market, meanwhile, shot up six percent at the opening on optimism that the controversial appointment could mark the beginning of the end for Rousseff, who is presiding over the worst recession in 25 years.

“The market is celebrating the end of this government,” said economic analyst Andre Leite of TAG Investimentos.