ACCRA, Ghana -An American president who has "the blood of Africa within me" praised and scolded the continent of his ancestors Saturday, asserting forces of tyranny and corruption must yield if Africa is to achieve its promise.

"No country is going to create wealth if its leaders exploit the economy to enrich themselves, or if police can be bought off by drug traffickers," he said in a speech to Parliament.

"No business wants to invest in a place where the government skims 20 percent off the top, or the head of the Port Authority is corrupt. 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, even if occasionally you sprinkle an election in there," he said, "and now is the time for that style of governance to end."

He added: "Africa doesn't need strongmen, it needs strong institutions."

The son of a white woman from Kansas and a black goat herder-turned-academic from Kenya, Obama delivered an unsentimental account of squandered opportunities in postcolonial Africa.

The first U.S. black president spoke with a bluntness that perhaps could only come from a member of Africa's extended family.

But he also offered words of encouragement.

"Yes you can," Obama declared, dusting off his campaign slogan and adapting it for his foreign audience.  He called upon African societies to seize opportunities for peace, democracy and prosperity.

"This is a new moment of great promise," he said. "To realize that promise, we must first recognize a fundamental truth that you have given life to in Ghana: Development depends upon good governance. That is the ingredient which has been missing in far too many places, for far too long. That is the change that can unlock Africa's potential."

Obama was on a 21-hour visit to the West African nation to highlight that country's democratic tradition and engagement with the West. His visit, his first to sub-Saharan Africa as president, was greeted as a "spiritual reunion" Saturday by Ghanian legislators.

Before the flight home, Obama visited Cape Coast Castle, a seaside fortress converted to the slave trade by the British in the 17th century. In its dungeons, thousands of shackled Africans huddled in squalor before being herded onto ships bound for America.

He, his wife Michelle, their daughters and the first lady's mother toured the grounds as a festive crowd of thousands milled outside, pounding drums and dancing in the streets. Obama smiled and waved, pausing after he exited the motorcade, before disappearing with his family and entourage into the courtyard. Michelle Obama is the great-great granddaughter of slaves.

Earlier, people lined the streets, many waving at every vehicle of Obama's motorcade as it headed toward a meeting at Osu Castle, the storied coastline presidential state house, before his speech to Parliament. "Ghana loves you," said a billboard.

The Obama administration sought a wide African audience for the president's speech, inviting people to watch it at embassies and cultural centers across the continent.

The 33-minute address was in part a splash of cold water for Africans who blame colonialism for their problems.

Obama spoke of the indignities visited upon Africans from the era of European rule. He said his grandfather, a cook for the British in Kenya, was called "boy" by his employers for much of his life despite his being a respected village elder. He said it was a time of artificial borders and unfair trade.

But he said the West is not to blame "for the destruction of the Zimbabwean economy over the last decade, or wars in which children are enlisted as combatants." Nor for the corruption that is a daily fact of life for many, he said.

"Africa is not the crude caricature of a continent at perpetual war," he said. Yet for "far too many Africans, conflict is a part of life, as constant as the sun. There are wars over land and wars over resources. And it is still far too easy for those without conscience to manipulate whole communities into fighting among faiths and tribes.

"These conflicts are a millstone around Africa's neck."

Obama started his day with typical calm. Wearing a gray T-shirt and gym pants, he walked through the lobby of his hotel almost unnoticed at 7:30 a.m. local time on his way to the downstairs gym for a workout.

A short time later, his motorcade left the hotel, passed under hovering military helicopters and arrived for a delayed welcome ceremony with President John Atta Mills.

"I can say without any fear of contradiction that all Ghanaians want to see you," Mills said. "I wish it were possible for me to send you to every home in Ghana."

The castle visit mirrored ones paid by Clinton and George W. Bush to the slave-trading post of Goree Island, Senegal -- with the added impact of Obama's mixed-race background and history-making election.

In Ghana, too, Obama followed in Clinton's footsteps. In 1998, a surging crowd cheered Clinton in Accra's Independence Square and toppled barricades after his speech. Clinton shouted, "Back up! Back up!", his Secret Service detail clearly frantic.

Bush's reception last year was less tumultuous, but equally warm. At a welcoming banquet, then-President John Kufuor noted huge increases in U.S. development aid and AIDS relief -- and named a highway after Bush.

Obama avoided scheduling large public events, wishing to keep emotions in check in a singular moment in African-American diplomacy.

The president pledged U.S. partnership in Africa's growth. Specifically, he said he would make sure U.S. aid gets to the people who need it most, such as farmers and entrepreneurs, not Western consultants and administrators.

That's why $3.5 billion in food assistance will focus on new methods and technologies for farmers, instead of simply sending U.S. goods to Africa, he said.

Obama flew to Ghana after the G-8 summit in L'Aquila, Italy, approved a new $20 billion food security plan. It aims to help poor nations in Africa and elsewhere to avert mass starvation during the global recession.

He also had a cordial first meeting with Pope Benedict XVI. In their half-hour private audience at the Vatican, the two reviewed Mideast peace and anti-poverty efforts, aides reported. They also discussed abortion and stem cell research at length, subjects of disagreement between them.