Brazilian President Jair Bolsonaro fired Luiz Henrique Mandetta as minister of health Thursday, after the two officials sparred publicly over the need for social distancing to fight Latin America’s largest coronavirus outbreak.

The country has reported more than 29,000 cases and more than 1,760 deaths from covid-19, the disease caused by the virus, numbers second only to the United States in the Western Hemisphere. Given Brazil’s sharply limited testing, actual cases and deaths are believed to be significant undercounts.

But much of the country’s focus in recent days was on widespread speculation that Bolsonaro was about to fire Mandetta, after the minister criticized the president on a popular news show for refusing to abide by the Health Ministry’s social distancing guidelines.

Bolsonaro described Mandetta’s departure as a “mutual divorce.”

“I do not condemn, I do not recriminate, and I do not criticize Minister Mandetta,” Bolsonaro told reporters at the Planalto presidential palace in Brasilia. “He did what, as a doctor, he thought he should do at the time. Isolation, increasingly, became a reality. But we cannot make decisions that destroy the work that has already been done.”

He named oncologist Nelson Teich as his new health minister.

“Everything will be analyzed in a scientific way,” Teich said. “There is a complete alignment between the president, myself and the ministry. We are working to make sure society returns to normal life as quickly as possible.”

Lucas Barreto, a senior representative of Bolsonaro’s government in the country’s Senate, resigned in protest.

“I’m leaving because firing Luiz Henrique Mandetta is absurd,” he told reporters.

The move comes as hospitals and clinics teeter on the brink of collapse. Emergency rooms in Amazonas state are running at capacity, with 95 percent of intensive care beds and ventilators occupied. Rio de Janeiro’s famed Maracana soccer stadium has been converted to a makeshift hospital to accommodate coronavirus patients. Gravediggers in the country’s largest cemeteries are working overtime to bury the dead.

Bolsonaro, meanwhile, has repeatedly downplayed the severity of the outbreak — dismissing the virus as a “little flu,” shrugging off social distancing recommendations from the World Health Organization and sharing videos calling for an end to the country’s lockdown.

“Gradually we have to open employment in Brazil,” he said Thursday. “The great humble masses cannot stay at home.”

His push to restart the economy set up a direct confrontation with Mandetta, who became a voice of resistance within the administration. A pediatric orthopedist who has served in Brazil’s National Congress since 2010, Mandetta insisted that businesses shut down and people stay home to reduce the spread of the virus.

Bolsonaro largely ignored those calls. On a visit with Mandetta last weekend to a pop-up hospital outside Brasilia, the president walked into a crowd, took off his mask, extended his hand for a supporter to kiss and autographed jerseys.

It was too much for the minister.

“Brazilians don’t know whether they should listen to their health minister or to their president,” Mandetta told the Globo news program Fantástico on Sunday.

Those who think relations between President Trump and infectious-disease chief Anthony S. Fauci are awkward might want to consider Bolsonaro and Mandetta.

Mandetta clearly and consistently walked back Bolsonaro’s erroneous claims on covid-19 with science and data. When deaths began to soar, Bolsonaro said the virus appeared to be going away; Mandetta warned of “tough days” ahead. When Bolsonaro touted an unproven cure for the virus — “This medicine here, hydroxychloroquine, is working everywhere,” he claimed in a video on Facebook and Twitter — Mandetta said he would not endorse widespread use of the drug without a peer-reviewed study. (Facebook and Twitter removed the videos.)

The health minister’s insistence on facts and figures clashed with Bolsonaro’s freewheeling approach, which often involves impromptu social media provocations with misinformation and conspiracy theories.

“Bolsonaro’s style has never been tied to facts,” said Anya Prusa, a senior associate at the Wilson Center’s Brazil Institute. “He prefers a more informal, off-the-cuff engagement. It is a style that served him well during the election, but it has not served him well as a leader.”

Bolsonaro’s approval ratings have fallen to a record low of 28 percent during the outbreak, according to an XP Investments poll published last week. Sixty-eight percent of those surveyed, in contrast, said Mandetta and his Health Ministry were doing a good or excellent job.

Those numbers weren’t lost on Bolsonaro, who said he wouldn’t hesitate to fire any members of his cabinet who “became stars.”

When speculation surfaced last week that Bolsonaro was ready to fire Mandetta, Brazilians protested from quarantine, banging pots and pans from their windows. Mandetta called a news conference Monday to announce that he was still on the job. But on Tuesday, he reportedly told his team that he expected to be dismissed by the end of the week.

It was Mandetta who announced the news, in a tweet.

“I just received notice from President Jair Bolsonaro of my resignation from the Ministry of Health,” he wrote. “I want to thank you for the opportunity I was given, to lead our [public health system], to launch a plan to better the health of Brazilians and to plan the combat of the coronavirus pandemic, this great challenge that our health system faces. . . . I wish my replacement success in his role as minister of health.”

Later, he addressed his now former staff at a news conference.

“Don’t be afraid,” he said. “Don’t do things one millimeter differently than you know how to do. I’m leaving this ministry, but I know I am leaving the best team behind. We have to unconditionally defend life, [the public health system], and science.”

The president of the Brazilian Medical Association said Teich has the group’s “total support.”

“He is respected by the medical class, a technically minded manager and highly prepared to lead the ministry of health,” Lincoln Lopes Ferreira said.

The news of Mandetta’s dismissal was greeted with more pot-banging. Shouts of “Killer!” and “Bolsonaro out!” could be heard in Rio de Janeiro.

“Mandetta was fired because he was unwilling to give up scientific and medical principles for the Brazilian people,” said Major Olímpio, a senator from Sao Paulo and former Bolsonaro ally. “Good luck to the new minister, but better luck to the Brazilian people and to public health.”

Bolsonaro’s political rivals have urged the people to ignore the president.

“Don’t follow the guidelines of the president of the republic,” said João Doria, governor of Sao Paulo state. “He does not lead the population correctly and unfortunately does not lead Brazil in the fight against the coronavirus and in the preservation of life.”

Doria, also a former Bolsonaro ally, this month called for a strict lockdown in his state, Brazil’s most populous.

Some critics said Bolsonaro’s opposition to Mandetta was strategic. By positioning himself as the health minister’s rival and a champion for the economy, he was shielding himself from blame for the inevitable recession that will follow the country’s lockdown.

“For Bolsonaro, the facts don’t matter. What matters is the narrative he constructs,” said Guilherme Casarões, a political scientist at the Getúlio Vargas Foundation, a university in Sao Paulo.

“The political narrative here is convenient because it transfers responsibility for the crisis and the economic collapse to other operatives,” Casarões said. “He can shrug off responsibility while he casts himself as the person who tried, against the will of the system, the governors and the media, to keep the economy going.”