Brazilian Senate President Renan Calheiros speaks during a session of the Senate in Brasilia on December 8, 2016. (Evaristo Sa/AFP/Getty)

BRASILIA — For more than 24 hours this week, nobody knew who was the head of Brazil's Senate. The Senate leader, Renan Calheiros, spent Tuesday avoiding a legal clerk who tried to serve him an order for his removal on embezzlement charges. That order, issued by a judge on Brazil's highest court, was also rejected by Senate leaders. And the chamber's vice president said that he wouldn't assume the Senate presidency.

Although Brazilian politics have always been messy, this week’s showdown has taken the chaos to a new and dangerous level.

Political analysts say the last time a standoff of this magnitude occurred, the military launched a coup, leading to two decades of military rule. The crisis appeared to be defusing Wednesday evening as the full Supreme Court ruled that Calheiros could stay in his job while he faces trial. But the episode showed how shaky Brazil's political institutions are. In the past six months, the country has impeached a president and jailed the speaker of the house, while five Cabinet ministers have stepped down or have been removed because of allegations of corruption. 

“In a democracy, for the Senate to take on the judicial branch and the Supreme Court is unprecedented. What the Senate is doing is very grave, because it is defying Brazil’s judicial power,” Carlos Ari Sundfeld, a legal scholar, told Globo, Brazil’s largest broadcast network.

Brazilian Senate President Renan Calheiros (center) leaves his office in Brasilia on Dec. 7. (Joedson Alves/European Pressphoto Agency)

Here's how the imbroglio started: On Tuesday, a Supreme Court justice ruled that the Senate leader had to step down to stand trial on charges that he embezzled $1.7 million in government money several years ago. (Calheiros has said that he is innocent). Given these charges, the justice argued, Calheiros could no longer occupy his post because he is in the direct line of succession to the president.

Calheiros's refusal to step down escalated a months-long brawl between Brazil's activist judges and a defiant Congress. Brazil’s judiciary has been cracking down on corruption in recent years. An investigation into Petrobras, the state oil giant, has put nearly 200 politicians and business executives behind bars since 2014. But the swelling investigations have unnerved many lawmakers, who fear they could be targeted, too. Last week, the House voted to gut an anti-corruption bill and put in place penalties for judges who overstep their bounds. The Senate was expected to vote on the measures this week.

The bill has put Congress at odds with the majority of Brazilians, who support the corruption crackdown, according to a recent poll. Thousands of Brazilians took to the streets in major cities over the weekend, denouncing the attempt to weaken the judiciary and calling for Calheiros to step down.

On Tuesday, a court clerk spent hours trying to serve him the order of removal. The clerk waited outside Calheiros's home while the politician held meetings but was barred from entering, with the door closed in his face, according to Brazilian media reports. The clerk was reportedly told the Senate leader wasn't there. He then went to the Senate and waited two hours for Calheiros, who refused to sign the document.

Calheiros later said the judiciary was interfering in the legislative sphere.

“Democracy, even in Brazil, doesn’t support this kind of action,” he told reporters Tuesday.

The removal decision, which was made by a single judge, was reviewed by the full Supreme Court on Wednesday. It ruled that Calheiros could remain on the job but would no longer be second in line for the presidency while the process was underway.

The fight threatened to further destabilize Brazil’s recession-weakened economy. Calheiros has been an important ally of President Michel Temer in corralling support for budget cuts to revive the economy. If the Senate leadership changed, it could have shifted the vote, expected in the coming weeks.

Investors will hardly welcome the new turmoil — they have been timid in returning to Brazil since the impeachment of former president Dilma Rousseff this year.

The Senate's behavior “breeds insecurity, because it shows that at any moment something can erupt in Brazil that can impact fiscal reforms,” said Lucas de Aragao, an analyst at Arko Advice, a political analysis firm in Brasilia. “It creates even more uncertainty, and investors hate uncertainty.”