Ghana's president, John Evans Atta Mills, has died suddenly, aged 68.

Mills, who was only months away from completing his first term in office, cancelled meetings and was taken to hospital at midday on Tuesday suffering from an unspecified illness.

A statement from the president's office, signed by the chief of staff, confirmed his death several hours later, after growing speculation and a near communications blackout in the capital city, Accra.

"It is with a heavy heart that we announce the sudden and untimely death of the president of the republic of Ghana," the statement said.

The announcement prompted an outpouring of grief as people across the political divide united in paying their respects. "This is our president who has died in office, we join all Ghanaians in mourning, we send our deepest condolences to his wife and family," said Jake Obetsebi Lamptey, the chairman of the opposition New Patriotic party. "As a mark of respect, the party is suspending all its activities."

MPs were summoned to Ghana's parliament house to swear in John Dramani Mahama, the former vice president, and given reassurances that the death of Mills would not spark a constitutional crisis. No president has ever died in office in the history of Ghana, which gained independence from Britain in 1957.

Mahama, who made an emotional speech describing Mills as a "father, friend, mentor and … senior comrade", said that the country was "deeply saddened and distraught" and declared one week of mourning in Ghana.

News of the president's death follows weeks of rumours about his health, prompted by a decline in public appearances and a medical trip to the US, which he insisted was for a routine check-up.

When Mills was elected in 2009, questions were raised about his fitness to lead the country. At least two false reports announcing his death have previously circulated in Ghana.

Mills was preparing to seek a second term in elections due in December.

Mills, a professor of tax law for 25 years, who studied at the University of London, was expected to lead a close contest for the ruling party, the National Democratic Congress.

The news has shocked other African countries, where there have been a number of deaths in office in recent years. Nigeria's president Goodluck Jonathan, who succeeded president Umaru Yar'Adua after he died in office in 2010, expressed his condolences.

A statement from the Nigerian presidency said: "On behalf of himself, the government and people of Nigeria, President Jonathan extends sincere condolences to late President Mills' family as well as the government and people of Ghana.

"The president assures the people of Ghana of the sympathy and solidarity of the people of Nigeria as they mourn late President Mills who did his best during his tenure to carry forward the process of democratic consolidation and socio-economic development in Ghana."

Ghanaian commentators praised the relative speed with which Mills' death was announced, two hours after doctors at the 37 Military Hospital in Accra failed to resuscitate him.