The new six-year term will let Chavez consolidate his control over Venezuela's economy, possibly by extending a wave of nationalizations, and continue his support for left-wing allies in Latin America and around the world.
"This has been the perfect battle, a democratic battle," Chavez thundered from the palace balcony late on Sunday, holding up a replica of the sword of independence hero Simon Bolivar.
"Venezuela will continue along the path of democratic and Bolivarian socialism of the 21st century." Turnout was a record 80 percent of registered voters, boosting Chavez's democratic credentials despite critics' depiction of him as a dictator.
The victory was considerably slimmer than his win by 25 percentage points in 2006, reflecting growing frustration at his failure to fix problems such as crime, blackouts and corruption.
"I WILL BE BETTER"
In a nod to those complaints, Chavez said he would be more focused in his new term beginning on January 10.
"Today we start a new cycle of government, in which we must respond with greater efficacy and efficiency to the needs of our people," he said. "I promise you I'll be a better president."
A retired lieutenant colonel who first won fame with a failed 1992 coup, Chavez has become Latin America's main anti-U.S. agitator, criticizing Washington while getting close to its adversaries, including Cuba, Syria and Iran.
A decade-long oil boom has given him tens of billions of dollars for social investments that range from free health clinics to new apartment complexes, helping him build a strong following among the poor.
Following his victory on Sunday, Chavez could order new nationalizations in some largely untouched corners of the economy, including the banking, food and health industries. He took advantage of his landslide win in 2006 to order takeovers in the telecoms, electricity and oil sectors.
But any recurrence of the pelvic cancer which has already forced him to undergo three operations in Havana since June 2011 could derail his plans.
Opposition leaders were crushed by the loss. It followed nearly a month of euphoria among Capriles supporters as the 40-year-old polished his stump speeches, held increasingly fervent rallies and appeared be to gaining ground in the polls.
"We are all hurt and sad but not disappointed. It was an incredible campaign," said housewife Teresa Perez, 51.
"Now I don't know what's going to happen with Chavez in power for six more years."
The youthful state governor put on a brave face, hailing his "house-by-house" campaign as the start of a long road to changing the direction of the country.
"I gave it my all and I'm proud of what we built," a subdued Capriles told supporters at his campaign headquarters.
"I will continue to work for Venezuela."
Though Capriles was indisputably the strongest candidate to face Chavez since the leftist leader was elected in 1998, few in the opposition thought the fight was fair.
Chavez made ample use of state television and spent 47 hours in "chain" broadcasts that force other local television stations to carry speeches peppered with political commentary.
He also handed out houses and pensions financed with state funds, often in ceremonies that glorified his administration, while warning that the opposition would cancel such programs.
The spending spree has weakened Venezuela's finances and may force a currency devaluation in early 2013, which would likely spur inflation that has been a top complaint among voters.
The election result is likely to prompt a sell-off in Venezuelan bonds, which have jumped in recent weeks on Wall Street optimism about a possible Capriles win.
"Going forward, we believe the market is likely to, as in recent years, continue to look at Venezuela as a gradually deteriorating macro story and trade it increasingly as an oil play," Goldman Sachs said in a research note.
Relations with Washington are also likely to remain on edge, though Venezuelan oil has continued to flow to the United States over the years despite diplomatic tensions.
IS THIS OBAMA'S VISION FOR AMERICA