Mr. Buhari, who leads the continent’s most populous nation, is under particular pressure to respond to the attacks, as some in his country have criticized his handling of security. Nigeria has been plagued by violent Islamist groups like Boko Haram in the north, and killings thought to be perpetrated by Fulani herdsmen.

Adekeye Adebajo, a Nigerian scholar who leads the Institute for Pan-African Thought and Conversation at the University of Johannesburg, said that the Nigerian president’s critics had used what had been perceived as his weak response to the South African riots as “another stick with which to beat Buhari.”

Nigerians will begin leaving South Africa on Wednesday, said Mr. Adama, the Nigerian consul general in Johannesburg, in an interview.

The flights will be paid for by Air Peace, he said, a Nigerian company that has volunteered to help its citizens.

The government will kick in funds if necessary, he added. About 600 people will leave on two flights, but many more have contacted officials to express interest in leaving, he said.

President Cyril Ramaphosa of South Africa has repeatedly condemned the riots as well as xenophobia. On Sunday, he called lawlessness “a crime against our prosperity and stability as a nation.”

“Those who want to upset our public order,” he said in a statement, “must expect to face the gravest impact of the law.”