his visit to Kenya.
Standing alongside President Uhuru Kenyatta outside State House on Saturday, Obama answered a journalist's question on gay rights by drawing equivalence between homophobia and racism.
"As an African-American in the United States I am painfully aware of what happens when people are treated differently under the law," Obama said.
The comparison is particularly stinging in Kenya, which, like other African countries, has a proud history of resisting and overcoming colonial rule by white foreigners.
"When you start treating people differently –- because they're different –- that's the path whereby freedoms begin to erode, and bad things happen," said Obama, adding that treating people differently "because of who they love is wrong, full stop."
"I've been consistent all across Africa on this," said Obama, who previously spoke in support of gay rights during a visit to Senegal in 2013.
Then, President Macky Sall replied that his country was "not ready" to decriminalise homosexuality, which is illegal in 35 African countries and carries the death penalty in four, according to campaign group Amnesty International.
On Saturday, Kenyatta repeated his argument that, for Kenyans, gay rights is "really a non-issue". He said it was an area of disagreement for Kenya and the US.
"There are some things we don't share, that our society, our culture, don't accept," Kenyatta said.
Edna Kendi, a 29-year old software developer was unimpressed by Obama publicly advocating gay rights. "He has to respect our culture," she said. "People can be gay but they should do so in private and quietly."
Kendi urged Obama to "stick to issues that are pertinent to the visit," for her, corruption and trade.
Moses Abok, a 49-year old motorbike taxi driver waiting for customers beneath a shady jacaranda tree, echoed Kenyatta's view.
"To me, it doesn't matter. The spirit of gayism is inside just a few people," he said using a common Kenyan term for homosexuality. "It's not a big deal for us."
But Abok also welcomed Obama's words. "What he said is we should value all people, we shouldn't alienate or eliminate those people, because they are part of us, they are human beings," he said.
Ruo Maina, a 50-year old businessman in the manufacturing industry who had popped out to buy the Sunday papers, said what you do at home is nobody's business.
"As long as you do it in private, we don't care," he said. Maina was not interested in public debates on gay rights, but added that Kenya's vocal anti-gay extremists are equally indulging in unnecessary "provocation".
"We don't need to be saying it is deviant," he said.
Deputy President William Ruto periodically addresses evangelical Christian churches to warn against homosexuality. There is "no room" for gays in Kenya he told worshippers in May, and in July railed against the US for allowing "gay relations and other dirty things."Anti-gay firebrand Irungu Kangata leads a cross-party caucus seeking to have the country's existing anti-homosexuality laws –- which include a maximum 14-year sentence –- to be strictly applied and makes frequent media appearances to explain that "gayism" is a lifestyle choice that can and should be unmade.
Vincent Kadala, an aspiring politician whose Republican Liberty Party has no seats in parliament, threatened to rally 5,000 naked men and women in order to show Obama "the difference between a man and woman".
The promised protest attracted a lot of media attention but was never held.