CARACAS — President Hugo Chavez died Tuesday afternoon after a long struggle with cancer, the government announced, leaving behind a bitterly divided nation in the grip of a political crisis that grew more acute as he languished for weeks, silent and out of sight in hospitals in Havana and Caracas.
With his voice cracking and close to tears, Vice President Nicolas Maduro said that he and other officials had gone to the military hospital where Chavez was being treated, sequestered from the public, when ‘‘we received the hardest and most tragic information that we could transmit to our people.’’
Within short order, police officers and soldiers were highly visible as people ran through the streets, calling loved ones on cellphones, rushing to get home. Caracas, the capital, which had just received news that the government was throwing out two US military attaches it accused of sowing disorder, quickly became an enormous traffic jam. Stores and shopping malls abruptly closed.
As darkness fell, somber crowds congregated in the main square of Caracas, some people crying. Chavez supporters set fire to tents and mattresses used by university students who had chained themselves together in protest several days ago to demand more information about Chavez’s condition.
‘‘Are you happy now?’’ the Chavez supporters shouted as they ran through the streets with sticks. ‘‘Chavez is dead! You got what you wanted!’’
Chavez’s departure from a country he dominated for 14 years casts into doubt the future of his socialist revolution. It alters the political balance in Venezuela, the fourth-largest foreign oil supplier to the United States, but also in Latin America, where Chavez led a group of nations intent on reducing US influence in the region.
Former US representative Joseph P. Kennedy II mourned the death of Chavez, who was a key partner with Kennedy in his efforts to provide heating oil to needy families through his Boston-based nonprofit, Citizens Energy Corp.
“President Chavez cared deeply about the poor of Venezuela and of other nations around the world and their abject lack of even basic necessities, while some of the wealthiest people on our planet have more money than they can ever reasonably expect to spend,” Kennedy said in a statement. “There are close to two million people in the United States who received free heating assistance, thanks to President Chavez’s leadership. Our prayers go out to President Chavez’s family, the people of Venezuela, and all who were warmed by his generosity.”
The relationship between Kennedy and Chavez dates back to 2005, when the Venezuelan leader, who controlled the nation’s oil industry during his tenure, began delivering crude oil at no charge to a Citizens affiliate, which then resold it and used the money to pay for oil deliveries to America’s poor.
In January, Citgo Petroleum Corp., which is owned by a subsidiary of Venezuela’s state-run oil company and has donated oil for the assistance program, announced that more than 200 million gallons had been donated over the last eight years. The campaign this winter is expected to help more than 100,000 families in 25 states plus the District of Columbia, Citgo said.
Kennedy has faced criticism over the years for his relationship with Chavez, a fiery leftist known in the United States for his anti-American rhetoric.
The former congressman, whose television ads thanking Venezuela have become a staple in New England households, has said repeatedly that he asked major oil companies in the United States and elsewhere to join the program, but only Chavez agreed to participate.
“Some people say it’s bad politics to do this,” Kennedy said in one Citizens TV ad that ran several years ago. “I say it’s a crime against humanity not to because no one, no one, should be left out in the cold.”
A Citizens spokesman declined to comment when asked how Chavez’s death may affect Citizens. A Citgo spokesman could not immediately be reached.
Kennedy’s son, current US Representative Joseph P. Kennedy III, said in a statement that his “thoughts and prayers” were with Chavez’s family.
“In this time of transition, it is my hope that the United States and Venezuela can build a productive relationship for the future,” the younger Kennedy said.
Chavez, 58, changed Venezuela in fundamental ways, empowering and energizing millions of poor people who had felt marginalized and excluded.
But Chavez’s rule also widened society’s divisions. His death is sure to bring more changes and vast uncertainty as the nation tries to find its way without its central figure.
The Venezuelan Constitution says the nation should ‘‘proceed to a new election’’ within 30 days when a president dies in the first four years of his term, and Foreign Minister Elias Jaua said in a television interview that Maduro would take the helm in the meantime.
The election itself is likely to pit Maduro, whom Chavez designated as his political successor, against Henrique Capriles Radonski, a young state governor who lost to Chavez in a presidential election in October.
But there has been heated debate in recent months over clashing interpretations of the constitution, in light of Chavez’s illness, and it is impossible to predict how the post-Chavez transition will proceed.
“We, your civilian and military companions, Commander Hugo Chavez, assume your legacy, your challenges, your project, accompanied by and with the support of the people,’’ Maduro told the nation.
Only hours earlier, the government seemed to go into a state of heightened alert as Maduro convened a crisis meeting in Caracas of Cabinet ministers, governors loyal to the president and top military commanders.
Taking a page out of Chavez’s time-tested playbook, Maduro warned in a lengthy televised speech that the United States was seeking to destabilize the country. He said the government had expelled two US military attaches, accusing one of seeking to recruit Venezuelan military personnel. He called on Venezuelans to unite as he raised the specter of foreign intervention.
Chavez was given a diagnosis of cancer in June 2011, but throughout his treatment he kept many details about his illness secret, refusing to say what kind of cancer he had or where in his body it occurred.
He had three operations from June 2011 to February 2012, as well as chemotherapy and radiation treatment, but the cancer kept coming back. The surgery and most other treatments were done in Cuba.
Then on Dec. 8, just two months after winning reelection, Chavez stunned the nation by announcing in a somber televised address that he needed yet another surgery.
That operation, his fourth, took place in Havana on Dec. 11. In the aftermath, grim-faced aides described the procedure as complex and said his condition was delicate. They eventually notified the country of complications, first bleeding and then a severe lung infection and difficulty breathing.
After previous operations, Chavez often appeared on television while recuperating in Havana, posted messages on Twitter or was heard on telephone calls made to television programs on a government station. But after his December surgery, he was not seen again in public.
Chavez’s aides eventually announced that a tube had been inserted in his trachea to help his breathing and that, as a result, he had difficulty speaking. It was the ultimate paradox for a man who seemed never at a loss for words, often improvising for hours on television.
As the weeks dragged on, tensions rose in Venezuela, and the situation turned increasingly bizarre. Officials in Chavez’s government strove to project an image of business as usual and deflected inevitable questions about a vacuum at the top. At the same time, the country struggled with an out-of-balance economy.
The opposition, weakened after defeats in the presidential election in October and elections for governor in December, in which its candidates lost in 20 of 23 states, sought to keep pressure on the government.
Then officials suddenly announced Feb. 18 that Chavez had returned to Caracas. He arrived unseen on a predawn flight and was installed in a military hospital.
Travis Andersen of the Globe staff contributed to this report.