This year, Mr. Trump was said to have referred to some nations in Africa in an insulting manner. The remarks prompted outrage across the continent. President Nana Akufo-Addo of Ghana reacted strongly to the disparaging remarks, saying at the time, on Twitter, that Ghana “will not accept such insults, even from a leader of a friendly country, no matter how powerful.”

A trip to several African nations to make amends by Rex W. Tillerson, then the secretary of state, was cut short, and Mr. Tillerson was fired on his way home.

On Wednesday, some of the protesters spoke about Mr. Trump in their outrage at the military deal.

“We are saying that President Akufo-Addo should listen to the people of this country,” said Samuel Okudzeto Ablakwa, a member of Parliament who took part in the demonstrations. “He is not co-president with President Trump of the U.S.A. He is the president of Ghana.”

He and other opposition lawmakers had boycotted the parliamentary vote on the deal, saying in a statement that it was a “betrayal of the Ghanaian people by surrendering our sovereignty and threatening the peace and stability of Ghana.”

This week, Koku Anyidoho, the deputy general secretary of the opposition party, the National Democratic Congress, was charged with treason for suggesting that the protests could be the start of a process that culminates in civil revolt and the ouster of the president.

Officials in the American Embassy in Accra, played down the terms of the agreement, saying it would include no more than a small storage structure and several shipping containers, and the site would be used as a staging area for military exercises and storage.

They emphasized that there were no plans to create a base in Ghana or to permanently station American troops in the country, one of the continent’s most stable democracies.