IF HUGO CHAVEZ is an autocrat, how could he be in danger of losing the Venezuelan presidency in an election on Sunday? The question, posed by one of Mr. Chavez’s dwindling band of American supporters, is a fair one: Polls show a race to the wire between the caudillo and challenger Henrique Capriles Radonski. An opposition victory would mean an epochal change of political direction in one of the world’s largest oil producers, with far-reaching consequences for Cuba and other leftist Latin American regimes.

The answer begins with the fact that Mr. Chavez, like his allies Vladimir Putin and Mahmoud Ahmadinejad, feels obliged to stage elections; the totalitarianism of Cuba or North Korea would risk rebellion by his population and international isolation. So elections are held — but in an environment that heavily favors the regime. Mr. Chavez controls Venezuela’s courts, election commission and most television channels, which bombard the population with propaganda. That includes hours-long appearances by the president on all channels simultaneously. Mr. Capriles is allowed three minutes of air-time per day.

According to a report by the Committee to Protect Journalists, even media not directly controlled by the government have been reluctant to report critically on Mr. Chavez. Many voters, too, are intimidated by high-tech polling machines that read their fingerprints; polls show that they suspect their votes will not be secret. Those not motivated by fright might be lured by greed: The government has amassed a list of 3 million people it has promised new homes. There are about 12 million likely voters.

That Mr. Chavez is in danger of losing in spite of all this is testimony to the havoc he has wreaked in what was once Latin America’s richest country. At more than 20 percent, inflation is the highest in the region and is accompanied by chronic shortages of food, basic consumer goods and power. The country’s infrastructure is crumbling: Within the last two months an explosion at a state oil refinery killed 50 people, and a major highway bridge collapsed. Perhaps worst of all for average citizens, violent crime has become epidemic under Mr. Chavez. The murder rate, which has more than tripled, is one of the five highest in the world. Drug traffickers have made Venezuela a hub for shipments to the United States and Europe with the help of senior government officials, including the current defense minister.

Fortunately, Venezuela’s opposition has evolved from a collection of feuding has-beens to a united and dynamic movement spearheaded by youth who long to push the country onto the modernizing paths of Brazil, Chile and Mexico. Mr. Capriles has survived imprisonment and systematic harassment by Mr. Chavez while remaining a committed liberal democrat who cites Brazil’s social democrats as his model. A tireless campaigner, Mr. Capriles has visited more than 300 municipalities, while Mr. Chavez — visibly weakened by what several reports have said is a terminal case of cancer — has mostly stuck to television.

Mr. Chavez’s illness probably means that his days as Venezuela’s leader are numbered anyway. The question now is whether he will give way if he loses on Sunday. Venezuela’s neighbors, and the Obama administration, should be ready to react if he attempts to remain in power by force.