After making his speech Mr Obama visited a former slave fort
US President Barack Obama, on his first trip to sub-Saharan Africa since taking office, has said Africa must take charge of its own destiny in the world.
Mr Obama told parliament in Ghana during a one-day stay that good governance was vital for development.
Major challenges awaited Africans in the new century, he said, but vowed that the US would help the continent.
The US president's trip came at the end of a summit of eight of the world's most powerful nations, held in Italy.
Ghana was chosen as the destination for the president's visit because of its strong democratic record.
After his speech, Mr Obama headed to Cape Coast Castle, a seaside fortress converted to the slave trade by the British in the 17th Century. He was accompanied by his wife, Michelle, a descendant of African slaves, and both of his young daughters.
People crowded into a public area outside the fort to greet Mr Obama, with those unable to get a place in the throng climbing onto nearby roofs and filling balconies just to catch a glimpse of the US leader.
Speaking after a tour of the fort, Mr Obama said the fort should be a source of hope as well as repository of painful memories.
"It reminds us that as bad as history can be, it's always possible to overcome," he said.
Earlier in the day, Mr Obama spoke to members of parliament after a breakfast meeting with Ghanaian President John Atta Mills.
He wore a broad grin as he was greeted at the podium by a series of rousing horn blasts from within the hall.
Development depends upon good governance. And that is a responsibility that can only be met by Africans
"Congress needs one of them," Mr Obama joked, before turning to more serious matters.
"I have come here to Ghana for a simple reason," the US president said: "The 21st Century will be shaped by what happens not just in Rome or Moscow or Washington, but by what happens in Ghana as well."
Delivering a message that "Africa's future is up to Africans", Mr Obama conceded that the legacy of colonialism had helped breed conflict on the continent.
"But the West is not responsible for the destruction of the Zimbabwean economy over the last decade, or wars in which children are enlisted as combatants," he added.
He praised Ghana's own progress, governance and economic growth, saying Ghana's achievements were less dramatic than the liberation struggles of the 20th Century but would ultimately be more significant.
"Development depends upon good governance," Mr Obama told legislators. "That is the ingredient which has been missing in far too many places, for far too long.
"And that is a responsibility that can only be met by Africans."
'Yes you can'
Expanding on his message, Mr Obama said four key areas were critical to the future of Africa and of the entire developing world, citing democracy, opportunity, health and the peaceful resolution of conflict.
Andrew Harding, BBC News, Accra
The speech has gone down extremely well. This is a country that has been enormously proud to play host to Mr Obama and referred to him as a brother. People say endlessly that he is part of the family and they are expecting a great deal of him.
It was a very broad-ranging speech but Mr Obama has an ability because of his heritage, his Kenyan father, to reach out and speak to Africans in a way that I think most foreign leaders would find very difficult.
There are very few barriers for Mr Obama in this conversation that he is trying to initiate with Africans and I think that this speech will have ticked many, many boxes.
This is Mr Obama trying to link Africa into the international community.
He hailed Ghana's democratic society, calling for strong parliaments, honest police, independent judges and a free press across Africa.
However, there were some blunt words directed at other countries, many of which have been undermined by despotic leaders and corrupt politicians.
"Africa doesn't need strongmen, it needs strong institutions," Mr Obama told his audience.
"No person wants to live in a society where the rule of law gives way to the rule of brutality and bribery. That is not democracy, that is tyranny."
He pledged to continue strong US support for public healthcare initiatives in Africa, and called for sensible use of natural resources such as oil in the face of the threat of climate change.
"Africa is not the crude caricature of a continent at war," Mr Obama added. "But for far too many Africans, conflict is a part of life, as constant as the sun. He described wars as a "millstone around Africa's neck".
"You have the power to hold your leaders accountable, and to build institutions that serve the people," Mr Obama said, describing freedom as Africa's "inheritance" and urging the continent to beat disease, end conflict and bring long-lasting change.
Barack Obama's speech was welcomed by Ghanaians of all ages
In an echo of his presidential election campaign, he drew his speech to a close with a version of his trademark slogan: "Yes you can," he told the gathered legislators.
Speaking to the BBC, Kenyan Prime Minister Raila Odinga welcomed the speech.
"We should stop blaming colonialism for our under-development. We really need to address issues of governance, because I believe it is the mediocrity with which Africa has been governed that is responsible for our backwardness today."
Mr Obama arrived in the capital late on Friday, fresh from the G8 summit in Italy where heads of state agreed on a $20bn (£12.3bn) fund to bolster agriculture - the main source of income for many sub-Saharan Africans.
He left after dark on Saturday, offering a final thanks for his welcome.
"As somebody whose father comes from Africa I am pleased this visit has been particularly meaningful for me," Mr Obama said.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.