BRASILIA (Reuters) - Brazil’s Supreme Court on Wednesday overturned an injunction that ordered the indicted head of the Senate, Renan Calheiros, to step down, voting to allow him to continue in the post but not in the presidential line of succession.

Slideshow ( 5 images )

The 6-3 ruling defuses a clash between the top court and the Senate that threatened to derail spending cuts at the center of President Michel Temer’s plan to tame a widening budget deficit and end a two-year recession.

The removal of Calheiros, indicted last week on embezzlement charges, would have left the Senate leadership in the hands of a leftist senator whose Workers Party opposes the cutbacks due to go before the upper house next week.

The court’s decision means the approval of the legislation to place a constitutional ceiling on federal spending is assured. Investors consider the reform a crucial step for Brazil to regain its investment grade credit rating.

Calheiros, whose mandate in charge of the chamber expires when Congress goes into its Christmas recess in a few days, had refused to step down on Tuesday, heightening the standoff between the legislature and judiciary.

“Our confidence in Brazil’s judiciary and the separation of powers continues unshaken,” Calheiros said in a statement on Wednesday, having earlier criticized the court for exceeding its jurisdiction by trying to oust a Congressional leader.

Calheiros was second in line to Brazil’s presidency after the speaker of the lower house, as the nation currently has no vice president. Former vice president Temer replaced President Dilma Rousseff when she was placed on trial in May by Congress, which eventually voted to remove her.

In the plenary debate in the Supreme Court, Justice Marco Aurelio de Mello defended his injunction issued two days earlier, which was based on a majority vote by the court in November that no person indicted for a crime could be in the presidential line of succession.

But in Wednesday’s ruling, the majority decided that, while no indicted person can be in line for the presidency, that does not mean they have to step down from other positions.

The injunction against him intensified a confrontation between the judiciary and the legislature over attempts by lawmakers to shield politicians from corruption probes by curbing the powers of prosecutors.

Calheiros was indicted on Dec. 1 on charges of misusing public funds in a nine-year-old case involving child support for a daughter he had in an extramarital affair, including billing the Senate for car rentals with false contracts.

The president of the Senate faces 10 other corruption investigations, mostly in the sprawling bribery and kickback scandal centered on state-run oil company Petrobras. PETR4.SA

In a year of political turmoil in Brazil, the attempted ouster of Calheiros follows the removal of the former speaker of the lower house for hiding Swiss bank accounts and the impeachment of the left-leaning Rousseff.

Reports earlier on Wednesday that Calheiros would survive the injunction strengthened the real currency and pushed up the BOVESPA stock index .BVSP as investors welcomed the prospect that the spending cap would win approval on Dec. 13.

The government’s leader in Congress, Senator Romero Jucá, said the Senate would work overtime to recover lost time and the reform would be put to the vote on schedule on Tuesday.

Temer faces an uphill battle in 2017 to push through an unpopular reform of Brazil’s pension system as the country risks entering a third year of recession.