ACCRA, Ghana — The Supreme Court of Ghana ruled Thursday that the government’s decision to allow two former Guantánamo Bay detainees to live in the country was unconstitutional.

Last year, Ghana signed an agreement with the United States to allow the two detainees, Khalid Mohammed Salih al-Dhuby and Mahmmoud Omar Mohammed Bin Atef, both citizens of Yemen, to resettle in Ghana. The two were captured by Afghan forces in late 2001 and turned over to the United States, and detained at the American prison in Guantánamo Bay, Cuba, as enemy combatants for 14 years, accused of being members of Al Qaeda.

On Thursday, the Supreme Court justices ruled that Ghana’s government, then led by President John Dramani Mahama, erred in approving the detainees’ transfer, saying that the agreement with the United States was an international one that required approval by members of Parliament. Two Ghanaian citizens had brought the case before the court, accusing the government of illegally allowing the men to enter Ghana.

Chief Justice Sophia Akuffo said that unless the government submitted the agreement to Parliament for approval within three months, the two men would be returned to the United States.