RIO DE JANEIRO — Brazilian lawmakers on Wednesday night closed ranks to shield President Michel Temer from standing trial on obstruction of justice and corruption charges, sparing him in the second such case in just two months.

But prevailing in this case came at a steep political price for Mr. Temer, the most unpopular Brazilian leader in modern times. In recent weeks, the president made major concessions to congressional coalitions and steered hundreds of millions of dollars in federal funding to projects favored by lawmakers in an effort to secure the support of enough of them.

The motion to table the case got 251 votes, far more than the 172 the president needed. The number who wanted the case to move forward, 233, was slightly higher than during a similar session in August.

Mr. Temer, who according to recent polls is supported by roughly 3 percent of the population, did not address the outcome after the session ended late Wednesday night.