DAKAR, Senegal — President Obama on Thursday called the Supreme Court’s decision to overturn the Defense of Marriage Act a “victory for American democracy” and said he had directed his administration to find ways to make sure gay couples received the benefits for which they were now eligible.

“It’s my personal belief, but I’m speaking now as a president not as a lawyer, that if you marry someone in Massachusetts and you move somewhere else, you’re still married,” Mr. Obama told reporters at a news conference here during his second trip to sub-Saharan Africa since taking office. “We’re going to be evaluating all these issues.”

Standing next to President Macky Sall of Senegal, Mr. Obama also urged African nations that treat homosexuality as a crime, like Senegal, to make sure that gays and lesbians were not discriminated against by the government.

“When it comes to how the state treats people, how the law treats people, I believe that everybody has to be treated equally,” Mr. Obama said. The comment prompted a retort from Mr. Sall that his country is not “homophobic” even though its society is not yet ready to decriminalize homosexual behavior.