The president was addressing a meeting of Senegal's Civil Society Organization following his visit to a historic slave trade site, which he called a reminder of what can happen "when we're not vigilant in defense of what's right."
The president and his family visited the "Door of No Return" on Goree Island, about 20 minutes from Dakar, the last stop for African slaves sent to North America.
"Obviously, for an African-American, an African-American president, to be able to visit this site, I think, gives me even greater motivation in terms of human rights around the world," Obama said after the tour.
He called visiting the slave house a "very powerful moment" that helped him "fully appreciate the magnitude of the slave trade" and "get a sense in an intimate way" of the hardships slaves faced.
It also served as a reminder that "we have to remain vigilant when it comes to the defense of human rights," he said.
"I'm a firm believer that humanity is fundamentally good, but it's only good when good people stand up for what's right," Obama said. "And this is a testament to when we're not vigilant in defense of what's right, what can happen."
During a meeting with Senegalese activist organizations and others, Obama noted the pivotal role civic activism has played and still plays in Senegal's democracy.
"The leaders -- just for the press -- the leaders who are gathered here today, these are all representatives of civil society, which is incredibly strong here in Senegal," he said.
About 15 civil society representatives participated in the meeting, including human rights advocates, lawyers, civic activists from nongovernmental organizations, youth leaders and musicians.
The White House said discussions during a closed-door session focused on three themes -- transparency and accountability; youth employment, civic participation, and education; and the protection of universal human rights for all, including women, children, and minorities.
At a meeting with regional judges in Dakar, Obama said strong democracies depend on strong institutions, including an independent judiciary and respect for the rule of law.
"These men and women and the institutions that they represent are known for their integrity, their determination to deliver justice fairly -- sometimes in the face of threats, and sometimes in the face of intimidation," Obama said Thursday, the first full day of his visit to Africa. "But they understand that what makes for a strong democracy includes a strong judiciary -- one that's independent from politics; one that operates transparently so that citizens can have confidence that the process is free from undue influences; accountability -- because even judges are not above the law."
He said the rule of law is not only a foundation for governance but also for human rights and economic growth.
"It's a pillar of our democracy," he said.
He said he told Senegalese President Macky Sall "trade and investment around the world increasingly flow to places where there are rules and regulations that are fair and predictable, where assets and intellectual property are protected -- and the courts play a vital role in that process."
During a joint news conference with Sall, Obama said he hasn't spoken to Russian or Chinese leaders about national secrets leaker Edward Snowden because he doesn't want to damage broader relations with the countries, The Washington Post reported.
Obama said he was pursuing Snowden's extradition through established legal channels, while suggesting that ensuring sensitive national security information is not compromised was a higher priority than apprehending Snowden, who admitted leaking data about the National Security Agency's cellphone and Internet monitoring programs.
Snowden has been charged with several federal crimes, including two spy-related charges, and has been in hiding.
"I get why it's a fascinating story from a press perspective. I'm sure there will be a made-for-TV movie," Obama said. "The damage done was in respect to the initial leaks."
Asked about major U.S. Supreme Court rulings this week, Obama called the overturning of the federal Defense of Marriage Act, which denied many federal benefits to same-sex couples, a "victory for American democracy," the Post said.
He said his administration was reviewing statues to determine whether it can order all states to provide benefits to same-sex couples that are legally married.
He said the court "made a mistake" in overturning a key portion of the Voting Rights Act by not understanding the degree of voter suppression that remains.
"It was the cornerstone and culmination of years of struggle -- blood, tears and in some cases death," Obama said of the landmark civil rights law. "I might not be here as president if not for those who courageously fought to pass the Voting Rights Act."
Obama's visit to Africa was threatened to be overshadowed by the failing health of former South African President Nelson Mandela.
The 94-year-old anti-apartheid revolution leader remains in critical condition in a Pretoria hospital.
Obama, who has called Mandela a personal hero, isn't scheduled to see him when he visits Pretoria, South Africa, Saturday as part of a two-day visit to the country.
Those plans could change, if Mandela's family desires, an Obama administration official said.
Obama will visit Tanzania Monday.
In the evening, the two leaders exchanged toasts at the presidential palace.
Sall spoke of the "ancient, robust and trustworthy" ties that have developed through the centuries between Senegal and the United States despite "the dark hours of slavery."
"Our two countries are cooperating for peace and a safer world rid of scourges of terrorism and cross-border crime," Sall said. "I commend your leadership, particularly in these times when the situation here in the Sahara has become a global threat and deserves special attention. I hope our countries can put together a joint strategy in response to this new challenge.
"Today, as agreed to in Washington, I would like to confirm our will to forge ahead with you -- forge ahead for the promotion of democracy and good governance in the spirit of our commitments stemming from the last G8 Summit; forge ahead in opening new opportunities of partnership between our countries; forge ahead for the promotion of the youth for the growth and prosperity of our peoples in a safer world."
Obama responded by lauding Senegal's commitment to democracy.
"Mr. President, I salute you and your administration for seeking what you have called 'a new mindset, a new consciousness' -- government that upholds 'the sanctity of the public good,'" Obama said.
"I've seen the principles of democracy in Senegal's commitment to human dignity."
Susan Sarandon 'very excited' about daughter's pregnancy
Dennis Rodman pledges to end trips to North Korea