BRASILIA (Reuters) - Brazilian lawmakers rejected corruption charges against President Michel Temer on Wednesday evening, shelving a case that had threatened to oust a center-right leader who investors hope will bring Brazil’s budget deficit under control.

Slideshow ( 10 images )

The corruption case, involving the payment of bribes by meatpacker JBS SA JBSS3.SA, had paralyzed Temer's reform agenda for six months and weakened his government.

The lower house of Brazil’s Congress, which has the authority to decide whether a president should stand trial by the Supreme Court, voted 251-233 to throw out charges of obstruction of justice and organized crime filed by federal prosecutors.

The vote means that Temer is safe from prosecution while he remains president. But he is still subject to investigation and possible trial by lower courts after his term ends in late 2018.

While Temer’s opponents were far from the 342 votes - or two-thirds of the seats - needed to put him on trial, he got 12 votes less than in August when the lower house voted 263-227 to block an initial corruption charge against him.

The slip in support signals Temer will have trouble passing a pension reform bill that is crucial for plugging Brazil’s budget deficit. Many lawmakers are reluctant to back the reform, which would make Brazilians work more years before retirement.

The speaker of the house, Rodrigo Maia, said the shelving of the charges against Temer cleared the way for the government and Congress to move ahead with the pension reform debate.

Allies said Brazil could not afford the upheaval of removing a second president in little over a year, as Latin America’s largest economy struggles to overcome deep recession. Temer succeeded impeached leftist President Dilma Rousseff in 2016.

Opponents criticized Temer for making policy concessions and fast-tracking pork barrel spending to win votes to ensure his survival.

To please the powerful farm lobby that has two-fifths of the votes in the lower house, Temer agreed to lower fines for environmental damage. He attempted to relax a definition of slave labor, but was forced to backtrack after an outcry.

A few hours before the vote, Temer was taken to hospital in pain due to a urinary tract obstruction, a health scare that triggered a brief selloff in financial markets.

His office said he underwent a bladder test by catheter and left the hospital later on Wednesday. Temer, 77, was recently diagnosed with a partial coronary artery blockage.

Brazil's benchmark Bovespa stock index .BVSP closed up 0.47 percent at 76,706 points after the house reached a quorum allowing the vote to go ahead.

Earlier, it touched session lows on the news that Temer was in the hospital. Stocks later pared losses and the currency was flat after his office gave details of his condition.