WASHINGTON — In January, when word got out that President Trump had disparaged African nations in vulgar terms during an Oval Office rant about immigration policy, his remarks were met with alarm and outrage by leaders and others on the continent.

But on Monday at the White House, both Mr. Trump and President Muhammadu Buhari of Nigeria, the first leader from sub-Saharan Africa to visit him at the White House, carefully avoided the topic, professing mutual respect for each other and their respective countries at a cordial news conference.

Lawmakers in the room with Mr. Trump in January said he had used the term “shithole countries” to describe African nations, an accusation he has previously denied. But he did not do so on Monday, instead appearing to try to justify its spirit by noting that many countries in Africa are riddled with problems.

“You do have some countries that are in very bad shape and very tough places to live in,” Mr. Trump said during a news conference with Mr. Buhari in the Rose Garden, asked by a reporter about his use of vulgarity to describe Africa. “But we didn’t discuss it because the president knows me, and he knows where I’m coming from, and I appreciate that.”