DAKAR, Senegal — President Barack Obama on Thursday praised the Supreme Court’s ruling on same-sex marriage as a “victory for American democracy” but clashed with his African host over gay rights in a sign of how far the movement has to go internationally.

Obama said recognition of gay unions in the United States should cross state lines and that equal rights should be recognized universally. It was his first chance to expand on his thoughts about the ruling, which was issued Wednesday as he flew to Senegal, one of many African countries that outlaw homosexuality.

Senegalese President Macky Sall rebuffed Obama’s call for Africans to give gays equal rights under the law.

“We are still not ready to decriminalize homosexuality,” Sall said, while insisting that the country is “very tolerant” and needs more time to digest the issue without pressure. “This does not mean we are homophobic.”

Obama said gay rights didn’t come up in their private meeting at the presidential palace, a mansion that looks somewhat similar to the White House. But Obama said he wants to send a message to Africans that while he respects differing personal and religious views on the matter, it’s important to have nondiscrimination under the law.

“People should be treated equally, and that’s a principle that I think applies universally,” he said.

A report released Monday by Amnesty International says 38 African countries criminalize homosexuality. In four of those — Mauritania, northern Nigeria, southern Somalia and Sudan — the punishment is death. These laws appear to have broad public support. A June 4 Pew Research Center survey found at least nine of 10 respondents in Senegal, Kenya, Ghana, Uganda and Nigeria believe homosexuality should not be accepted by society.

Papi Nbodj, a 19-year-old student who stood by the road to the presidential palace to see Obama’s arrival, said homosexuality is against the religious beliefs of most in Senegal.

“We are in a Muslim country, so we certainly cannot have it here,” he said. “And for me it’s not OK to have this anywhere in the world.”

Sall sought to reassure Obama that gays are not persecuted in Senegal. But under Senegalese law, “an improper or unnatural act with a person of the same sex” can be punished by up to five years in prison.

Ndeye Kebe, president of a human rights organization that works with homosexuals called Women’s Smile, disputed Sall’s contention that gays are not discriminated against.

“I know of around a dozen people who are in prison for homosexuality as we speak,” she said. “There wasn’t any real proof against them, but they were found guilty and they are in prison.”

And as recently as February of 2008, police rounded up men suspected of being homosexual after a Senegalese tabloid published photographs of a clandestine gay wedding in a suburb of Dakar. Gays went into hiding or fled to neighboring countries, but they were pushed out of Gambia by the president’s threat of decapitation.

As for Wednesday’s court ruling, Obama said he’s directing his administration to comb through every federal statute to quickly determine the implications of a decision that gave the nation’s legally married gay couples equal federal footing with all other married Americans.

He said he wants to make sure that gay couples who deserve benefits under the ruling get them quickly. Obama said he personally believes that gay couples legally married in one state should retain their benefits if they move to another state that doesn’t recognize gay marriage.

“I believe at the root of who we are as a people, as Americans, is the basic precept that we are all equal under the law,” he said. “We believe in basic fairness. And what I think yesterday’s ruling signifies is one more step towards ensuring that those basic principles apply to everybody.”

Obama also offered prayers for former South African President Nelson Mandela, who is gravely ill, ahead of Obama’s planned visit to his country this weekend. Obama said he was inspired to become political active by Mandela’s example in the anti-apartheid movement of being willing to sacrifice his life for a belief in equal treatment.

“I think he’s a hero for the world,” Obama said. “And if and when he passes from this place, one thing I think we’ll all know is that his legacy is one that will linger on throughout the ages.”

Hundreds awaited Obama behind barricades later at Goree Island on Africa’s westernmost point, where Africans were said to be have been shipped off into slavery across the Atlantic Ocean. Obama peered out at the crashing waves through the island’s “Door of No Return,” at first by himself and later joined by his wife, Michelle, and two daughters. Emerging minutes later, Obama said the site painted a powerful picture of the magnitude of the slave trade as he reflected on the ties many in the U.S. share with the continent.

“For an African-American, an African-American president, to be able to visit this site gives me even greater motivation in terms of human rights around the world,” he said.

Obama’s focus in Senegal is on the modern-day achievements of the former French colony after half a century of independence. Sall ousted an incumbent who attempted to change the constitution to make it easier for him to be re-elected and pave the way for his son to succeed him. The power grab sparked protests, fueled by hip-hop music and social media, that led to Sall’s election.

“Senegal is one of the most stable democracies in Africa and one of the strongest partners that we have in the region,” Obama said. “It’s moving in the right direction with reforms to deepen democratic institutions.”

But such people-powered democratic transitions are not always the story of the African experience. Fighting and human rights abuses limited Obama’s options for stops in his first major tour of sub-Saharan Africa since he took office more than four years ago. Obama is avoiding his father’s homeland, Kenya, whose president has been charged with war crimes, and Nigeria, the country with the continent’s most dominant economy. Nigeria is enveloped in an Islamist insurgency and military crackdown.

Obama’s itinerary in Senegal was designed to send a message, purposefully delivered in a French-speaking, Muslim-majority nation, to other Africans in countries that have not made the strides toward democracy that Senegal has. Obama also met with civil society leaders at the Goree Institute and visited the Supreme Court to speak about the importance of an independent judiciary and the rule of law in Africa’s development.

——

Associated Press writers Rukmini Callimachi and Robbie Corey-Boulet in Dakar and Julie Pace in Goree Island, Senegal, contributed to this report.

——

Follow Nedra Pickler on Twitter at https://twitter.com/nedrapickler