RIO DE JANEIRO — Just a few days ago, Brazil seemed to be turning a corner. The stock market was soaring. Bankers were cheering. The nation’s cutthroat lawmakers were lining up to curb spending. Inflation had been tamed.

Brazil, it appeared, was finally on the mend.

Then, in a matter of hours, it all started falling apart. President Michel Temer, long embroiled in graft scandals, suddenly became tangled in a new one, accused of taking millions of dollars in illicit payments and caught on tape discussing how to obstruct an anticorruption drive.

The allegations — including testimony released Friday in which executives at one of the world’s largest food companies accused him of taking about $4.6 million in illegal campaign contributions — have ignited broad calls for Mr. Temer’s resignation, sent markets whipsawing and set off fears that Brazil will slide back into the political and economic turmoil that has rattled it for the last two years.

The testimony, released by the Supreme Court, also described tens of millions of dollars in illicit payments into offshore accounts intended to benefit his impeached predecessor, Dilma Rousseff, and her mentor, former President Luiz Inácio Lula da Silva, both of whom have denied any wrongdoing in the matter.