CARACAS, Venezuela — President Hugo Chavez won re-election Sunday, defeating challenger Henrique Capriles Radonski and gaining six more years to cement his legacy and press ahead with his crusade for socialism in Venezuela.

With about 90 percent of votes counted, Chavez had more than 54 percent of the vote, and Capriles had 45 percent, National Electoral Council president Tibisay Lucena said. She said 81 percent of the nearly 19 million registered voters cast ballots, one of the largest turnouts in years.

Venezuela's President Hugo Chavez greets his supporters at the Miraflores presidential palace balcony in Caracas, Venezuela, Sunday, Oct. 7, 2012. Chavez won re-election and a new endorsement of his socialist project Sunday, surviving his closest race yet after a bitter campaign against opposition candidate Henrique Capriles. (photo credit: AP Photo/Fernando Llano)

Venezuela’s President Hugo Chavez greets his supporters at the Miraflores presidential palace balcony in Caracas, Venezuela, Sunday, Oct. 7, 2012. Chavez won re-election and a new endorsement of his socialist project Sunday, surviving his closest race yet after a bitter campaign against opposition candidate Henrique Capriles. (photo credit: AP Photo/Fernando Llano)

It was Chavez’s third re-election victory in nearly 14 years in office, though by a smaller margin than in 2006, when he won 63 percent of the votes.

Fireworks exploded in downtown Caracas, and Chavez’s supporters celebrated waving flags and jumping for joy outside the presidential palace.

Chavez won more than 7.4 million votes, beating Capriles by more than 1.2 million votes, Lucena said.

Chavez rallied thousands of supporters from a balcony of the presidential palace, holding up a sword that once belonged to 19th century independence hero Simon Bolivar.

“The revolution has triumphed!” Chavez told the crowd, saying his supporters “voted for socialism.”

The crowd responded chanting “Chavez won’t go!”

Capriles congratulated Chavez and told his supporters not to feel defeated.

“We have planted many seeds across Venezuela and I know that these seeds are going to produce many trees,” he told supporters in a speech late Sunday.

Chavez spent heavily in the months before the vote, building public housing and bankrolling expanded social programs providing benefits to poor families.

Capriles, a youthful state governor, became a strong challenger after winning a February primary and rallied an opposition that grew more united and better organized than in the past. But in the end, it was no match for Chavez’s electoral prowess.

Opposition presidential candidate Henrique Capriles talks to supporters and media members as he concedes defeat in the presidential elections at his campaign headquarters in Caracas, Venezuela, Sunday, Oct. 7, 2012. Venezuela's electoral council said late Sunday President Hugo Chavez has won re-election, defeating challenger Capriles. (photo credit: AP Photo/Ariana Cubillos)

Opposition presidential candidate Henrique Capriles talks to supporters and media members as he concedes defeat in the presidential elections at his campaign headquarters in Caracas, Venezuela, Sunday, Oct. 7, 2012. Venezuela’s electoral council said late Sunday President Hugo Chavez has won re-election, defeating challenger Capriles. (photo credit: AP Photo/Ariana Cubillos)

Israel and Venezuela’s tiny Jewish community were following the race with particular interest: Chavez has vilified the United States and Israel, cozied up to Iran and the Palestinians, and helped create an atmosphere of acute discomfort for the country’s Jews. By some estimates, more than half of the Jews in Venezuela have emigrated since he came to power.

Capriles, on the other hand, is the Catholic grandson of Jewish Holocaust survivors. He has been quoted saying that “my mother’s four grandparents were murdered in Treblinka,” and that his grandmother, who was in the Warsaw Ghetto “taught me not to hate anyone.” At a recent rally, he spoke of the need to defeat the “Goliath” Chavez, and described himself and all his supporters as “David.”

Some Venezuelans were nervous about what might happen if disputes erupt over the election’s announced outcome.

Just as polls closed on Sunday night, hundreds of young red-shirted Chavistas took to the streets on motorcycles and said they were ready to begin celebrating.

“Let them accept defeat,” Kleiver Gutierrez said of the opposition.

People holding posters of Chavez shouted to passing cars outside the Miraflores presidential palace.

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. “That’s why the people are going to re-elect Hugo Rafael Chavez Frias.”

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.

Maria Leonis was selling CDs of Chavez’s campaign theme music on a sidewalk next to a polling center. “Today I’ve sold about 100 CDs, just Chavez’s song,” Leonis said, adding that she supported Chavez because “I want to keep seeing change.”

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.”

The 40-year-old Capriles, a wiry former governor affectionately called “Skinny” by supporters, infused the opposition with new optimism, and opinion polls pointed to him giving Chavez his closest election contest ever.

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.