Around 30 heads of state attended the funeral of Hugo Chavez in a last goodbye to the charismatic but divisive Venezuelan leader who changed the face of politics in South America.

Mr Chavez died on Tuesday aged 58 after a two-year battle with cancer.

His death devastated millions of mostly poor supporters who loved him for putting the country's vast oil wealth at their service.

Huge crowds of "Chavistas" arrived early for the ceremony at a military academy where his body has been lying in state.

Many were dressed in the red of the ruling Socialist Party, carrying his picture and waving Venezuelan flags.

The late president's body is to be embalmed and shown "for eternity" at a military museum - similar to how communist leaders Lenin, Stalin and Mao were treated after their deaths.

His remains will lie in state for an extra seven days to accommodate the millions of Venezuelans who still want to pay their last respects.

More than two million people have so far filed past Mr Chavez's coffin behind a red rope at the grandiose military academy.

Among the leaders gathering in Caracas were close allies such as Ecuadorean President Rafael Correa, Brazil's current and former leaders, Dilma Rousseff and Luiz Inacio Lula da Silva, and Cuban President Raul Castro.

"Most importantly, he left undefeated," Mr Castro said, referring to Mr Chavez's four presidential election wins, among a string of other ballot victories in his 14-year rule.

Belarusian President Alexander Lukashenko and Iranian President Mahmoud Ahmadinejad were among the more controversial figures scheduled to attend the ceremony.

The United States, with whom Mr Chavez had a rocky relationship was not sending high level officials.

Former US Representative William Delahunt, US Representative Gregory Meeks, and the charge d'affaires from the US embassy will attend.

A government source said Mr Chavez slipped into a coma on Monday before dying the following day of respiratory failure.

The cancer had spread to his lungs, the source added.