HARARE, Zimbabwe — The wife of Zimbabwe’s president, Robert Mugabe, was whisked out of South Africa on Sunday, trailed by calls for her arrest after she was accused of beating a fashion model with an extension cord in a luxury hotel in Johannesburg.

The violent encounter between the president’s wife, Grace Mugabe, 52, who had sought diplomatic immunity afterward, and the model, Gabriella Engels, 20, who had filed assault charges, sparked outrage in South Africa and Zimbabwe and threatened to escalate into a diplomatic incident.

The South African authorities confirmed on Sunday that Mrs. Mugabe had been granted immunity. Foreign Minister Maite Nkoana-Mashabane said in a statement that she had been “acting in the interests of South Africa” in recognizing “the immunities and privileges” of Mrs. Mugabe.

The handling of the case drew intense criticism — it was at least the second time that Mrs. Mugabe has had a brush with the law in which she sought protection. In 2009, she was granted diplomatic immunity by Hong Kong after being accused of attacking a British photographer who took pictures of her shopping. (Mrs. Mugabe’s lavish shopping expeditions have been the subject of derision and denunciations at home.)

This time, she escaped arrest after Ms. Engels said Mrs. Mugabe had burst into the hotel room on Aug. 13 while she was visiting Robert Mugabe Jr., 25, and Chatunga Mugabe, 21, and began beating her with the extension cord as 10 bodyguards watched.

“There was blood everywhere,” Ms. Engels told a South African broadcaster. “She flipped and just kept beating me with the plug. Over and over. I had no idea what was going on. I was surprised. I needed to crawl out of the room before I could run away.”

Why she was beaten was not entirely clear, but Ms. Engels later filed charges and posted photos on social media showing a deep gash in her forehead, a bloodied scalp and bruises on her body.

Although South Africa is known for its robust judicial system and strong constitutional norms, its government has recently been taken to task for not enforcing international law. Last month, the International Criminal Court rebuked the government for failing to arrest Sudan’s president, who is wanted on war crimes and genocide charges, when he visited in 2015.

The decision to grant Mrs. Mugabe diplomatic immunity “continues a worrying trend by the South African government to prioritize protecting regional allies from prosecution over enforcing international and domestic criminal law,” said Hannah Woolaver, a senior lecturer in public international law at the University of Cape Town.

“As a private citizen who does not represent Zimbabwe internationally, unlike the head of state or head of government, she does not qualify for immunity under international law or under the relevant South African domestic law,” she said.

The first lady and President Mugabe, 93, had been in Pretoria, South Africa, for a summit meeting of southern African leaders when the scandal erupted. They left early Sunday, before the end of the summit meeting. Mrs. Mugabe was later seen greeting government and military officials at the airport in Harare, the state broadcaster ZBC reported.

Mr. Mugabe had said his wife visited South Africa, where her son lives, to get medical treatment for a leg injury. If that was the case, said Dr. Woolaver, she should not have been granted immunity.

Dr. Woolaver lamented that in practice, “it would be almost impossible to pursue any criminal charge now that Grace Mugabe is back in Zimbabwe, though it may well make her future travel to South Africa more complicated.”

Stephen Chan, a professor of world politics at the School of Oriental and African Studies, part of the University of London, said the decision to grant immunity “reflects the importance South Africa ascribes to good diplomatic relations with Zimbabwe.” He added, “That it took the South Africans three days to make up their minds to grant it suggests that there was a real problem as to whether immunity could be justified.”

Neither the Zimbabwean government nor Mrs. Mugabe have given a public explanation of the events. Repeated phone calls and text messages to a spokesman for the family were not answered.

Outraged rights activists have called on South African officials to turn the full force of the law on Mrs. Mugabe. Hordes of protesters gathered outside the summit meeting in Pretoria on Saturday, calling for her arrest. In a sign of the widening impact of the scandal, both countries grounded flights from the other nation. Even in Zimbabwe, critics piled on.

“Grace Mugabe should not even be given an option of a fine if she appears in court; she should go to jail,” said Linda Masarira, a Zimbabwean rights activist and leader of the Zimbabwe Activists Alliance.

At one point, there was speculation that Mrs. Mugabe had slipped out of South Africa to avoid prosecution. She did not attend the first ladies’ forum at the summit meeting. The police said she had failed to show up for a hearing. Then, the South African minister of police, Fikile Mbalula, said a “red alert” had been issued to ensure she did not return to Zimbabwe undetected.

Last week, Mrs. Mugabe’s legal representatives, including officials from Zimbabwe’s Ministry of Foreign Affairs, invoked diplomatic immunity to prevent any prosecution, the South African

Rashweat Mukundu, former director of the Media Institute of Southern Africa Zimbabwe, said, “It is a Catch-22 situation for South Africa as the Zimbabwe first lady is by extension of her relationship a diplomat of sorts, while at the same time South Africa must be seen to be protecting its citizens from harm and being tough on criminality.”

President Jacob Zuma of South Africa and Mr. Mugabe “were not going to allow this matter to deteriorate to the extent of damaging relations beyond what we see now,” Mr. Mukundu added.

A group representing Ms. Engels, AfriForum, vowed to push for a private prosecution of Mrs. Mugabe if the South African police did not bring a case against her.

Ms. Engels said that Mrs. Mugabe had accused her of living with the Mugabe brothers, who reside in an upscale Johannesburg suburb, Sandton. They have been in the news recently about their lavish lifestyle. The People’s Democratic Party in Zimbabwe has accused them of “spending taxpayers’ money like confetti,” according The Economist.

Mrs. Mugabe is a fierce guardian of her husband and his legacy. She has said her husband could rule from the grave. “If God decides to take him, then we would rather field him as a corpse” in the 2018 election, she said this year.

Mrs. Mugabe has emerged as a top contender to succeed him.

The diplomatic impasse, meanwhile, appeared to have affected some flights in and out of both countries. South African officials on Friday grounded an Air Zimbabwe flight at Johannesburg’s Tambo International Airport, claiming the plane did not have a foreign operator’s permit. Zimbabwe promptly blocked flights from South Africa’s government-owned airline.

In a sign that President Mugabe and his wife intended to keep a low profile for now, they did not attend a state funeral for a former minister in Harare on Sunday. Mr. Mugabe had been scheduled to preside. Instead, Vice President Phelekezela Mphoko officiated.