The ruling will not end a political crisis dogging president Temer, who is being investigated separately by federal prosecutors for corruption.
Brazil's top electoral court dismissed a case on Friday that threatened to unseat President Michel Temer for alleged illegal campaign funding in the 2014 election.
The ruling gives Temer, who was the running mate of impeached president Dilma Rousseff, some breathing room. However, it will not end a political crisis dogging the center-right leader, who is being investigated separately by federal prosecutors for corruption.
"We cannot be changing the president of the Republic all the time, even if the people want to," said the court's chief judge, Gilmar Mendes.
Mendes, who backed the impeachment of Rousseff, said the country should not expect the court to solve the current political crisis.
The acquittal will help Temer retain key coalition allies who will support his fiscal reform agenda approval in Congress. The austerity measures aim to bring a gaping budget deficit under control and restore investor confidence.
The electoral court, known as the TSE, voted 4-3 to acquit the Rousseff-Temer ticket, avoiding the annulment of their election and the removal of Temer from office, who took over from Rousseff last year in the midst of Brazil's worst recession.
Temer is likely to soon face separate charges for corruption and obstruction of justice in a case involving allegations of hush money paid to a potential witness in a massive graft scandal. The Supreme Court approved that investigation into the president late last month.
Temer, a third of his Cabinet and dozens of powerful congressmen are under investigation for corruption.
The TSE voted 4-3 on Thursday to not allow plea-bargain testimony from 77 executives of builder Odebrecht to be used as evidence in the election case. That testimony includes accusations the company funnelled millions in illegal funding to the 2014 Rousseff-Temer ticket. The exclusion of that evidence strengthened Temer's line of defence.
The separate investigation by prosecutors into Temer includes a secret recording of a conversation with a top executive of meatpacker JBS SA. In it, the president appears to condone paying bribes to an imprisoned former lawmaker to keep him from turning state's witness and providing potentially devastating testimony about graft.
Temer has denied any wrongdoing. But a one-time top aide to the leader, Rodrigo Rocha Loures, was caught on a police video released last month picking up a bag filled with 500,000 reais ($152,000) in cash from a JBS executive.