CARACAS, Venezuela — President Hugo Chavez won re-election and a new endorsement of his socialist project Sunday, surviving his closest race yet after a bitter campaign in which the opposition accused him of unfairly using Venezuela's oil wealth and his near total control of state institutions to his advantage.
Fireworks exploded over downtown Caracas amid a cacophony of horn-honking by elated Chavez supporters who waved flags and jumped for joy outside the presidential palace.
With 90 percent of votes counted, Chavez had more than 54 percent of the vote to 45 percent for challenger Henrique Capriles, an athletic 40-year-old former state governor who unified and energized the opposition while barnstorming across the oil-exporting nation.
But Capriles' promises to seriously address violent crime that has spun out of control, streamline a patronage-bloated bureaucracy and end rampant corruption proved inadequate against Chavez's charisma, well-oiled political machine and a legacy of putting Venezuela's poor first with generous social welfare programs.
Chavez will now have a freer hand to push for an even bigger state role in the economy and continue populist programs. He's also likely to further limit dissent and deepen friendships with U.S. rivals.
A Capriles victory would have brought a radical foreign policy shift including a halt to preferential oil deals with allies such as Cuba, along with a loosening of state economic controls and an increase in private investment.
It was Chavez's third re-election in nearly 14 years in office. It was also his smallest victory margin. In 2006, he won by 27 percentage points.
"I can't describe the relief and happiness I feel right now," said Edgar Gonzalez, a 38-year-old construction worker.
He ran through crowds of Chavez supporters packing the streets around the presidential palace wearing a Venezuelan flag as a cape and yelling: "Oh, no! Chavez won't go!"
"The revolution will continue, thanks to God and the people of this great country," said Gonzalez.
Voter turnout was an impressive 81 percent, compared to 74 percent in 2006. Chavez paid close attention to his military-like get-out-the-vote organization at the grass roots, stressing its importance at campaign rallies. The opposition said he unfairly plowed millions in state funds into the effort.
Chavez spent heavily in the months before the vote, building public housing and bankrolling expanded social programs.
"I think he just cranked up the patronage machine and unleashed a spending orgy," said Michael Shifter, president of the Washington-based Inter-American Dialogue think tank.
But Shifter also didn't deny the affinity and gratefulness Venezuela's poor feel for Chavez. "Despite his illness, I still think he retains a large emotional connection with a lot of Venezuelans that I think were not prepared to vote against him."
Chavez spoke little during the campaign about his fight with cancer, which since June 2011 has included surgery to remove tumors from his pelvic region as well as chemotherapy and radiation treatment. He has said his most recent tests showed no sign of illness.
In conceding defeat, Capriles told supporters not to feel defeated.
"We have planted many seeds across Venezuela and I know that these seeds are going to produce many trees," told a hall of supporters.
Despite winning a February primary that unified the opposition, Capriles proved no match for Chavez's electoral prowess.
David Valencia, a 20-year-old Capriles supporter, said he was disappointed but that he hadn't lost hope despite the loss.
"There is still a sense in our hearts of wanting a better country," he said.
One pro-Chavez voter, private bodyguard Carlos Julio Silva, said that whatever his faults, Chavez deserved to win for spreading the nation's oil wealth to the poor with free medical care, public housing and other government largess. The country has the world's largest proven oil reserves.
"There is corruption, there's plenty of bureaucracy, but the people have never had a leader who cared about this country," Silva said after voting for Chavez at a school in the Caracas slum of Petare.
At many polling places, voters began lining up hours before polls opened at dawn, some snaking for blocks in the baking Caribbean sun. Some shaded themselves with umbrellas. Vendors grilled meat and some people drank beer.
Chavez's critics say the president has inflamed divisions by labeling his opponents "fascists," ''Yankees" and "neo-Nazis," and it's likely hard for many of his opponents to stomach another six years of the loquacious and conflictive leader.
Some said before the vote that they'd consider leaving the country if Chavez won.
Gino Caso, an auto mechanic, said Chavez is power-hungry and out of touch with problems such as crime. He said his son had been robbed, as had neighboring shops.
"I don't know what planet he lives on," Caso said, gesturing with hands blackened with grease. "He wants to be like Fidel Castro — end up with everything, take control of the country."
Associated Press writers Fabiola Sanchez, Christopher Toothaker, Jorge Rueda and Vivian Sequera contributed to this report.
Ian James on Twitter: http://twitter.com/ianjamesap
Frank Bajak on Twitter: http://twitter.com/fbajak