Ghana's President John Atta Mills, who was suffering from throat cancer, has died in hospital in the capital, Accra.
A statement from his office said the 68-year-old died a few hours after being taken ill, but did not give details.
John Dramani Mahama, his vice-president, has been sworn in as his replacement in a ceremony in the capital.
Mr Atta Mills had ruled the West African country since 2009.
"It is with a heavy heart... that we announce the sudden and untimely death of the president of the Republic of Ghana," the president's office statement said.
He died in a hospital in Accra on Tuesday afternoon while receiving treatment, his office said.
While Mr Atta Mills' illness had always been a subject of great debate, it was never officially confirmed, correspondents say. He had always insisted he was well, and planned to seek re-election in December's poll.
According to a presidential aide, the leader had complained of pains on Monday evening and his condition had deteriorated.
He had recently returned to Ghana after visiting the US for medical checks.
The BBC's Sammy Darko, in Accra, says Mr Atta Mills' voice had been degenerating in the last few months.
Elizabeth Ohene, a journalist and member of Ghana's former government, said she had not believed the news at first, as there had been a number of false reports about his death.
"For the past three or four years there's been news he's been unwell and rumours of his death - twice - and he appeared with grim humour to say they were exaggerated, insisting he was well," she told the BBC's Focus on Africa programme.
Liberia's President Ellen Johnson-Sirleaf extended her condolences to Ghanaians, saying the news had come as a surprise.
"On a personal level his moderation and integrity stood out," Mrs Johnson-Sirleaf said, adding that Mr Atta Mills had played a strong role at the regional meetings they both attended.
US President Barack Obama also paid tribute, praising Mr Atta Mills as a "strong advocate for human rights and for the fair treatment of all Ghanaians", according to a White House statement.
Hours after the announcement, Mr Mahama was sworn in by the country's chief justice at an emergency session of parliament, in line with Ghana's constitution.
He will serve out the rest of Mr Atta-Mills' term, before elections which are scheduled for December.
Mr Atta Mills served as vice-president to former Ghanaian military ruler Jerry Rawlings between 1997 and January 2001.
He came to power after narrowly winning against a candidate from the then governing New Patriotic Party, Nana Akufo-Addo, in polls in December 2008.
His predecessor, John Kufuor, stepped down after having served the maximum permitted two four-year terms.
Under Mr Atta Mills' leadership, Ghana joined the ranks of the world's large-scale oil producers.