CARACAS, Venezuela (AP) — President Hugo Chavez was a former paratroop commander and self-styled "subversive" who waged continual battle for his socialist ideals. He bedeviled the United States and outsmarted his rivals time and again, while using Venezuela's vast oil wealth to his political advantage.

Chavez led one coup attempt, defeated another and was re-elected three times. Almost the only adversary it seemed he couldn't beat was cancer. He died Tuesday in Caracas at age 58, two years after he was first diagnosed.

The son of schoolteachers, he rose from poverty in a dirt-floor, mud-walled house, a "humble soldier" in the battle for socialism. He fashioned himself after 19th-century independence leader Simon Bolivar and renamed his country the Bolivarian Republic of Venezuela.

During more than 14 years in office, his leftist politics and grandiose style polarized Venezuelans. The barrel-chested leader electrified crowds with his booming voice, and won admiration among the poor with government social programs and a folksy, nationalistic style.

Opponents seethed at the larger-than-life character who demonized them on television and ordered the expropriation of farms and businesses. Many in the middle class cringed at his bombast and complained about rising crime, soaring inflation and government economic controls.

Chavez used his country's oil wealth to launch social programs that included state-run food markets, new public housing, free health clinics and education programs. While poverty declined during his presidency amid a historic boom in oil earnings, critics said he failed to use the windfall of hundreds of billions of dollars to develop the country's economy.

Inflation soared and the homicide rate rose to among the highest in the world

Before his struggle with cancer, the charismatic leader appeared on television almost daily, speaking for hours and breaking into song or philosophical discourse. He often wore the bright red of his United Socialist Party of Venezuela, or the fatigues and red beret of his army days — the same uniform he donned in 1992 while leading an ill-fated coup attempt that first landed him in jail and then launched his political career.

Story continues

The rest of the world watched as the country with the world's biggest proven oil reserves took a turn to the left under its unconventional leader, who considered himself above all else a revolutionary.

"I'm still a subversive," Chavez told The Associated Press in a 2007 interview, recalling his days as a rebel soldier. "I think the entire world has to be subverted."

Chavez was a master communicator and savvy political strategist, and managed to turn his struggle against cancer into a rallying cry, until the illness finally defeated him.

From the start, he billed himself as the heir of Bolivar, who led much of South America to independence, often speaking beneath the 19th-century liberator's portrait and presenting replicas of his sword to allies. He built a soaring mausoleum in Caracas to house the remains of "El Libertador."

Chavez also was inspired by his mentor Fidel Castro and took on the Cuban leader's role as Washington's chief antagonist in the Western Hemisphere after the ailing Castro turned over the presidency to his brother Raul in 2006. Like Castro, Chavez decried U.S.-style capitalism while forming alliances throughout Latin America and with distant powers such as Russia, China and Iran.

Supporters eagerly raised Chavez to the pantheon of revolutionary legends ranging from Castro to Argentine-born rebel Ernesto "Che" Guevara. Chavez nurtured that cult of personality, and even as he stayed out of sight for long stretches during his bout with cancer, his out-sized image appeared on buildings and billboard throughout Venezuela. The airwaves boomed with his baritone mantra: "I am a nation." Supporters carried posters and wore masks of his eyes, chanting, "I am Chavez."

In the battles Chavez waged at home and abroad, he captivated his base by championing Venezuela's poor.

"This is the path: the hard, long path, filled with doubts, filled with errors, filled with bitterness, but this is the path," Chavez told his backers in 2011. "The path is this: socialism."

On television, he would lambast his opponents as "oligarchs," scold his aides, tell jokes, reminisce about his childhood, lecture Venezuelans on socialism and make sudden announcements, such as expelling the U.S. ambassador or ordering tanks to Venezuela's border with Colombia.

Chavez carried his in-your-face style to the world stage as well. In a 2006 speech to the U.N. General Assembly, he called President George W. Bush the devil, saying the podium reeked of sulfur after the U.S. president's address.

At a summit in 2007, he repeatedly called Spanish Prime Minister Jose Maria Aznar a fascist, prompting Spain's King Juan Carlos to snap, "Why don't you shut up?"

Critics saw Chavez as a typical Latin American caudillo, a strongman who ruled through force of personality and showed disdain for democratic rules. Chavez concentrated power in his hands with allies who dominated the congress and justices who controlled the Supreme Court.

"El Comandante," as he was known, insisted Venezuela remained a vibrant democracy and denied charges that he sought to restrict free speech. But some opponents faced criminal charges and were driven into exile. His government forced the opposition-aligned television channel, RCTV, off the air by refusing to renew its license.

While Chavez trumpeted plans for communes and an egalitarian society, his rhetoric regularly conflicted with reality. Despite government seizures of companies and farmland, the balance between Venezuela's public and private sectors changed little during his presidency.

Nonetheless, Chavez maintained a core of supporters who stayed loyal to their "comandante" until the end.

"Chavez masterfully exploits the disenchantment of people who feel excluded ... and he feeds on controversy whenever he can," Cristina Marcano and Alberto Barrera Tyszka wrote in their book "Hugo Chavez: The Definitive Biography of Venezuela's Controversial President."

Hugo Rafael Chavez Frias was born on July 28, 1954, in the rural town of Sabaneta in Venezuela's western plains, the son of schoolteachers and the second of six brothers. He was raised by his grandmother, Rosa Ines, in a home with a dirt floor, mud walls and a roof made of palm fronds.

Chavez was a fine baseball player and hoped he might one day pitch in the U.S. major leagues. When he joined the military at age 17, he aimed to keep honing his baseball skills in the capital.

But between his army duties and drills, the young soldier immersed himself in the history of Bolivar and other Venezuelan heroes who had overthrown Spanish rule, and his political ideas began to take shape.

Chavez burst into public view in 1992 as a paratroop commander leading a military rebellion that brought tanks to the presidential palace. When the coup collapsed, Chavez was allowed to make a televised statement in which he declared that his movement had failed "for now." The speech, and those two defiant words, launched his career, searing his image into the memory of Venezuelans.

Two years later, he and other coup leaders were released from prison, and President Rafael Caldera dropped the charges against them.

After organizing a new party, Chavez ran for president in 1998, pledging to clean up Venezuela's entrenched corruption and shatter its traditional two-party system. At age 44, he became the country's youngest president, winning 56 percent of the vote.

After he took office on Feb. 2, 1999, Chavez called for a new constitution, and an assembly filled with his allies drafted the document. Among various changes, it lengthened presidential terms from five years to six and changed the country's name to the Bolivarian Republic of Venezuela.

By 2000, his increasingly confrontational style and close ties to Cuba disenchanted many of the middle-class supporters who voted for him, and the next several years saw bold attempts by opponents to dislodge him from power.

In 2002, he survived a short-lived coup, which began after large anti-Chavez street protests ended in shootings and bloodshed. Dissident military officers detained the president and announced he had resigned. But within two days, he returned to power with the help of military loyalists amid massive protests by his supporters.

Chavez emerged a stronger president.

He defeated an opposition-led strike that paralyzed the country's oil industry and fired thousands of state oil company employees.

The coup also turned Chavez more decidedly against the U.S. government, which had swiftly recognized the provisional leader who briefly replaced him. He created political and trade alliances that excluded the U.S., and he cozied up to Iran and Syria in large part, it seemed, due to their shared antagonism toward the U.S. government. Despite the souring relationship, Chavez kept selling the bulk of Venezuela's oil to the United States.

By 2005, Chavez was espousing a new, vaguely defined "21st-century socialism." Yet the agenda didn't involve a sudden overhaul to the country's economic order, and some businesspeople continued to prosper. Those with lucrative ties to the government came to be known as the "Bolivarian bourgeoisie."

After easily winning re-election in 2006, Chavez began calling for a "multi-polar world" free of U.S. domination, part of an expanded international agenda. He boosted oil shipments to China, set up joint factories with Iran to produce tractors and cars, and sealed arms deals with Russia for assault rifles, helicopters and fighter jets. He focused on building alliances throughout Latin America and injected new energy into the region's left. Allies were elected in Bolivia, Ecuador, Argentina and other countries.

Chavez also cemented relationships with island countries in the Caribbean by selling them oil on preferential terms while severing ties with Israel, supporting the Palestinian cause and backing Iran's right to a nuclear energy program.

All the while, Chavez emphasized that it was necessary to prepare for any potential conflict with the "empire," his term for the United States.

He told the AP in 2007 that he loved the movie "Gladiator."

"It's confronting the empire, and confronting evil. ... And you end up relating to that gladiator," Chavez said as he drove across Venezuela's southern plains.

He said he felt a deep connection to those plains where he grew up, and that when died he hoped to be buried in the savanna.

"A man from the plains, from these great open spaces ... tends to be a nomad, tends not to see barriers. What you see is the horizon," Chavez said.

Running a revolution ultimately left little time for a personal life. His second marriage, to journalist Marisabel Rodriguez, deteriorated in the early years of his presidency, and they divorced in 2004. In addition to their one daughter, Rosines, Chavez had three children from his first marriage, which ended before he ran for office. His daughters Maria and Rosa often appeared at his side at official events and during his trips. He had one son, Hugo Rafael Chavez.

After he was diagnosed with cancer in June 2011, he acknowledged that he had recklessly neglected his health. He had taken to staying up late and drinking as many as 40 cups of coffee a day. He regularly summoned his Cabinet ministers to the presidential palace late at night.

Even as he appeared with head shaved while undergoing chemotherapy, he never revealed the exact location of tumors that were removed from his pelvic region, or the exact type of cancer.

Chavez exerted himself for one final election campaign in 2012 after saying tests showed he was cancer-free, and defeated younger challenger Henrique Capriles. With another six-year term in hand, he promised to keep pressing for revolutionary changes.

But two months later, he went to Cuba for a fourth cancer-related surgery, blowing a kiss to his country as he boarded the plane.

After a 10-week absence, the government announced that Chavez had returned to Venezuela and was being treated at a military hospital in Caracas. He was never seen again in public.

On Tuesday, Cuban folk singer Silvio Rodriguez posted photos on his blog of a past encounter with Chavez, the Venezuelan leader singing along as he strummed a guitar.

"Goodbye forever, comandante," Rodriguez wrote.