Bystanders posted video on the net showing balls of fire rising over the Amuay refinery in Punto Fijo, among the largest in the world.

Government officials pledged to restart the refinery within two days and said the country has plenty of fuel to meet domestic needs as well as export commitments.

Saturday's explosion shattered walls of nearby shops, ripped out windows from homes and left the surrounding streets covered with rubble and twisted scraps of metal.

The president, Hugo Chávez, declared three days of mourning and ordered an investigation to determine the cause of the explosion. "This affects all of us," Chávez said by phone on state television. "It's very sad, very painful."

The vice-president, Elías Jaua, who travelled to the area in western Venezuela, said the dead included 18 national guard troops and six of the bodies had not yet been identified. Other officials said earlier that the dead included a 10-year-old boy.

In a neighbourhood next to the refinery, a shopkeeper, Yolimar Romero, said she was at her computer when a shockwave swept over the area shortly after 1am.

"At that instant, the whole house shook as if it were an earthquake," she said. "The windows went flying off with their frames and everything."

Electricity was knocked out, leaving Romero in the dark and her house filled with smoke. She found a torch and started looking for her husband and three children.

Outside on the street, the family saw scattered hunks of brick walls and ruins of a national guard post and about 20 other homes. Bodies were being pulled from buildings down the street.

At least 86 people were injured, nine of them seriously, the health minister, Eugenia Sader, said at a hospital where the wounded were taken. She said 77 people had suffered light injuries and had been released.

Flames reaching 30 metres into the night air still crackled almost 20 hours after the explosion occurred, giving off searing heat felt by the residents of the neighbourhood located approximately 300 metres from the refinery.

"This does not seem to be getting any better. I see and feel more and more flames," said Francisco Rojas, a 29-year-old taxi driver from the neighbourhood, as he loaded some of his belongings into a truck.

"I have a young daughter and my wife, and we don't want to take the risk of dying here," Rojas added.

Officials said firefighters had largely controlled the fire at the refinery on the Paraguana peninsula, where flames were still visible on Saturday night after billowing dark smoke all day.

The blast occurred about 1.15am when a natural gas leak created a cloud that ignited, the oil minister, Rafael Ramírez, said.

"That gas generated a cloud that later exploded and has caused fires in at least two tanks of the refinery and surrounding areas," Ramírez said.

Images shortly after the explosion showed the flames casting an orange glow against the night sky, and injured survivors on a stretcher and in a wheelchair. The bloodied bodies of victims were loaded onto pickup trucks.

Ramírez said a panel of investigators was being formed to determine the cause of the gas leak. A prosecutor had been appointed to lead the investigation and troops had been deployed to the area.

While the cause of the disaster remains unclear, some oil workers and critics of Chávez's government have recently pointed to increasing numbers of smaller accidents and spills as an indication of problems within the state-run oil company, PDVSA.

"We warned that something was going to happen, a catastrophic event," said Iván Freites, the secretary general of a 1,200-member union of oil and natural gas industry workers in Falcón state, where the refinery is located. He spoke in a telephone interview from an area near the refinery, where he could see the flames raging in the distance.

The refinery complex's general manager, Jesus Luongo, denied that a lack of maintenance was to blame, saying that in the past three years more than £3.8bn has been invested in maintaining the country's refineries.

Ramírez said the explosion had hit an area of storage tanks, damaging nine tanks.

"All of the events happened very quickly," Ramírez said. "When we got here in the middle of the night, at 3 or 3.30 in the morning, the fire was at its peak."

The oil minister said that supplies of fuel had been cut off to part of the refinery and that firefighters were using foam to extinguish the flames in one of the remaining tanks.

"This regrettable and sad event is controlled, is under control," Ramírez said on television, while plumes of smoke continued to billow.

Amuay is part of the Paraguaná refinery complex, which also includes the adjacent Cardón refinery. Together, the two refineries process about 900,000 barrels of crude a day and 200,000 barrels of petrol. Venezuela is a major supplier of oil to the US and a member of the Organisation of Petroleum Exporting Countries.

Ramírez said PDVSA should be able to "restart operations in a maximum of two days".

"We want to tell the country that we have sufficient inventories of fuel. We have 10 days of inventory of fuel," Ramírez said. He said the country's other refineries were operating at full capacity and would be able to "deal with any situation in our domestic market".

A PDVSA official said the country also has enough supplies to guarantee its international commitments. The official spoke on condition of anonymity because he wasn't authorised to speak publicly about the matter.

In terms of international oil markets, the disaster is not likely to cause much of a ripple, said Jason Schenker, an energy analyst and president of Austin, Texas-based Prestige Economics. Noting that other refinery accidents and shutdowns regularly occur around the world, he said: "There's likely to be relatively limited impact on global crude or product pricing."

Schenker said: "The real tragedy is that these events continue to happen, not just in Venezuela but everywhere. It is a dangerous business."

Gustavo Coronel, an energy consultant and former PDVSA executive, called the tragedy "probably the worst one the oil industry has had in many years.

"Accidents happen, of course, although the problem with PDVSA is the inordinate amount of accidents that have taken place during the last years," Coronel said. Considering the overall record, "we are not talking about bad luck but about lack of maintenance and inept management," he said.

Freites, who has worked at the refinery for 29 years, said workers had repeatedly alerted PDVSA officials to problems that they feared could lead to an accident. "We've been complaining about problems and risks, including fires, broken pipes and a lack of spare parts," Freites said.

One opposition group comprising former PDVSA employees, Gente del Petróleo, or Oil People, said it could not yet pass judgment on the cause of the explosion. But it noted there had been ample concerns about lack of maintenance and poor management.

The group said in a statement that since 2003, 79 other serious accidents have been reported at Paraguaná, killing a total of 19 workers and injuring 67.

The opposition leader, Henrique Capriles, who is challenging Chávez in the presidential election on 7 October, expressed condolences to the victims and their families.

"We Venezuelans are one, and we grow in the face of this type of situations," Capriles said.