The fury was not limited to those countries directly mentioned, however.
El Salvador’s government sent a formal letter of protest. Earlier in the week, the United States announced it was rescinding Temporary Protected Status for about 200,000 Salvadorans living in the United States.
In Brussels, a European Union lawmaker, Gianni Pittella of Italy, told The Associated Press that Mr. Trump “had forgotten to engage his brain before talking.”
Vicente Fox, a former president of Mexico who has frequently clashed with Mr. Trump, demanded of him: “With what authority do you proclaim who’s welcome in America and who’s not.” (He also suggested that Mr. Trump’s vulgar word was better used to describe his own mouth.)
Michaëlle Jean, a former governor general of Canada who is now the secretary general of Francophonie, which comprises 84 states that share French as a language, called the comments “disturbing.”
“It is such an insult before humanity,” Ms. Jean, a native of Haiti, who after the earthquake became Unesco’s special envoy to the Caribbean nation, told the Canadian Press. “For the first representative of the United States of America to speak in such a manner is quite troubling and offensive.”
Unsurprisingly, some of the strongest reactions were in Africa.
“I am shocked by President Trump’s comments on Haiti and Africa,” President Macky Sall of Senegal wrote on Twitter. “I reject them and condemn them vigorously. Africa and black people deserve the respect and consideration of all.”
Botswana’s government issued a statement calling the president’s remark “highly irresponsible, reprehensible and racist.”
Mr. Trump has a growing history of disparaging and ill-informed remarks about both Africa and Haiti. In June, he was reported to have said that Nigerians in the United States would never “go back to their huts” in Africa.
In September, he spoke of a country called Nambia, which does not exist. (The White House later clarified that he had meant to say Namibia.)
Mr. Trump said in a tweet on Friday that he had a “wonderful relationship with Haitians,” but last June, The New York Times reported, he grumbled in another immigration meeting that Haitians “all have AIDS.” The White House denied that report.
The celebrated Haitian-American writer Edwidge Danticat said that Mr. Trump’s comments gave her chilling memories of arriving to the United States in 1981, the year before federal authorities included being Haitian as one of the four increased risk factors for contracting the new, and at the time fatal, disease, H.I.V. and AIDS.
“As a kid, I was beaten up in school for being Haitian,” Ms. Danticat said at a literary seminar in Key West, Fla., on Friday. “In Miami, there was a boy who killed himself when his girlfriend found out he was Haitian.”
“There are real consequences,” she said. “People lose their jobs. People get harassed. It’s like putting a target on our backs.”
The Haitian ambassador to the United States, Paul G. Altidor, told NPR on Friday it was “quite regrettable that we’re not discussing about the earthquake and how Haiti is moving forward.”
“Unfortunately, we fear, once again Haiti finds itself in the midst of a very negative narrative in the U.S., and we are hoping this conversation will be an opportunity to address the Haiti conversation in the U.S. once and for all,” he said.
Across social media on Thursday night and Friday, Africans and Haitians shared pictures of beautiful beaches, tree-lined streets and glamorous tourist resorts captioned with the insult.
Online and offline, in cafes and shops across Africa, some wondered why the United States had spent millions of dollars to build massive embassies in countries which Mr. Trump held in such low esteem. Others speculated that if Mr. Trump visited their countries, he might revise his assumptions. Still others said that Mr. Trump may have had a point, citing the endemic corruption, public health challenges and poverty in many African nations.
“That’s why we’re being termed a shithole,” Andrew Mataso, 55, a business executive, said on a busy street in Nairobi, Kenya.
Vincent Omondi, who lives in the sprawling working-class neighborhood of Kibera, in Nairobi, pointed out that the United States had a long relationship with people from the countries Mr. Trump criticized.
“The USA,” he wrote in a Facebook message, “was partly built by slaves from the ‘shithole’ countries.” But Mr. Omondi said poverty and economic dysfunction across Africa lent support to Mr. Trump’s point.
“Do I care?” Mr. Omondi said. “Not really, but such a statement coming from the leader of the ‘free world’ should serve as a wake up call for Africans to build Africa.”
Oyenka Nwenze, 26, a broadcaster, was stocking up on cooking ingredients for the weekend at a supermarket in the Silverbird shopping mall in Abuja, Nigeria.
“For someone in that position he should know better, and he doesn’t even try, he isn’t attempting to expand his knowledge base,” Mr. Nwenze said. “In Africa we are normal human beings.”
Under rainy skies in Port-au-Prince, Haiti, many people were reflecting on the earthquake, remembering loved ones who died.
Michelet Desulme, 31, a motorcycle taxi driver, said he agreed with Trump’s assessment of Haiti. “The way our country is,” he said, “the way it’s not functioning, is this what his country is like?”
The State Department appeared to have gone into damage-repair mode.
Without directly referring to the president’s contentious statement, the State Department’s main Africa account said on Twitter that “the United States will continue to robustly, enthusiastically and forcefully engage in Africa, promoting this vital relationship, and to listen and build on the trust and views we share with our African partners.” The tweet was framed as a comment on a meeting of African ministers that the department hosted in November.
Not everyone accepted that gesture, and some people were fearful of speaking in opposition to what they perceived as American policy. In Dakar, Senegal, diners at a beachside restaurant that serves Moscow mules and mojitos declined to express their views about Mr. Trump, fearing they might be denied visas to visit the United States.
Babacar Faye, a tailor in Dakar, tuned his radio to another station Friday morning when discussion of Mr. Trump’s comments was broadcast. His remarks were not surprising, Mr. Faye said.
“White people in general don’t like black people,” he said. “They just pretend to like us, but they don’t.”
Phoebe Mutetsi in Kigali, Rwanda, said she was not falling for it.
“Trump is a troll,” she said. “He is trolling the world. Don’t feed the troll.”