Brazil's election court voted Friday against stripping President Michel Temer of his office in a major boost to his chances of beating a gathering corruption scandal.

The Supreme Electoral Tribunal (TSE) considering charges that Temer's election in 2014 should be annulled because of the role of corruption money -- voted 4-3 to acquit the embattled center-right president.

The verdict spared recession-ravaged Brazil its second leadership crisis in 14 months, following the impeachment of leftist president Dilma Rousseff last year and her replacement by her then-vice president Temer.

The lead judge on the TSE case, Justice Herman Benjamin, headed the push to sack Temer, saying that systemic undeclared donations and bribes from big Brazilian corporations fatally undermined the 2014 Rousseff-Temer election in Latin America's biggest country. "This is enough to invalidate the mandate," he said.

But in a marathon process during which each of the seven judges voted one by one, giving detailed arguments, the tide turned.

Finally, the TSE's president Gilmar Mendes cast the deciding vote with a call for cool heads and stability at a time of national turmoil. "You don't switch the president of the republic every hour," he said. "There are serious proven facts but not enough to annul the mandate."

Clearly feeling strengthened, Temer fired a dramatic shot in a separate obstruction of justice case that he faces by refusing a demand by prosecutors to provide a written deposition by Friday.

He demanded that the probe against him be shut down instead.

Temer's legal problems on top of corruption probes opened against a third of his cabinet and many of his congressional allies come just as Brazil is struggling to exit its worst recession in history.

If the TSE had removed Temer, Congress would have had to pick a new interim president to serve the rest of his term to the end of 2018.

- 'Diving into the mud' - Temer greeted the verdict as "a sign that the national institutions continue to guarantee the smooth functioning of Brazilian democracy," his spokesman said afterward.

However, the decision caused dismay among those pushing for Brazil to face up to its corruption problem. "No democracy can come out unharmed from the institutional free-for-all that Brazil is going through," said Rio State University political scientist Mauricio Santoro, slamming "the degradation of the rules and of public life.

"The TSE's decision sends the judiciary diving into the same mud as the other branches." Attention will now turn to Temer's battle against the parallel case in which he is accused of obstruction of justice and corruption.

Prosecutor General Rodrigo Janot alleges that Temer agreed to payments of hush money to former lower house of Congress speaker Eduardo Cunha, who is in prison for corruption. Janot had ordered Temer to answer 82 questions in writing by late Friday as part of his building of the case.

Rather than meet the deadline, Temer's lawyers branded the probe a "comedy," an "inquisition" and "arrogant."

Temer says the central piece of evidence in Janot's probe a secretly made audio recording of a conversation he had with a meatpacking industry tycoon was doctored.