Hugo Chávez calls on all parties to accept the election result. Reuters

Venezuelan voters turned out in droves on Sunday to give their verdict on the rule of Hugo Chávez after the most closely fought presidential election since the former tank commander won power in 1998.

Amid fears of unrest if the result was close, national guards armed with AK47s and teargas patrolled the streets. Both sides had warned that the other was preparing to destabilise the country.

But at the polling booths the mood was peaceful and, though partisan, fiercely democratic. The lines of voters outside the polling station in La Florida curled beyond the Cervantes high school, past the housing blocks and up the hill as far as the eye could see. Locals said they had never seen such a turnout, a sign of the interest generated by the vibrant political race and what some believed was an outside chance of an upset.

"In every election, there are a lot of people here, but never like this. People want a change," said a 50-year-old housewife, Marcoline Uzcategui, as she stood outside the polling station. "I don't want to carry on living like this. I have a faint illusion that things may change this time, but Chávez has all the power so I don't want to get my hopes up too high."

Others said they would stick with the president. "Chávez will win because he has supported the people," said Alfredo Alvarez, a lawyer. "He's administered funds as he should."

The show of people power was impressive. Even Chávez's critics acknowledge that he has encouraged greater public participation in decision-making.

Venezuela’s Hugo Chávez, facing his most serious challenge since he was elected president in 1998, greets crowds in Caracas. Photograph: Boris Vergara/EPA

The 58-year-old president has defied many of his critics by fighting back from cancer this year. Although he has not been as prominent on the campaign trail as in the past, a huge rally in Caracas on Thursday showed his formidable campaign power and charisma.

His 40-year-old opponent, Henrique Capriles, has won kudos for an energetic campaign but in an election day tweet acknowledged he was the underdog. "Today we decide the future of our Venezuela," Capriles tweeted. "Today we are millions of Davids! God will be our guide," he added, referring to his depiction of the vote as the biblical underdog's battle against Goliath.

Ahead of the vote, opinion polls suggested the president would be re-elected, albeit by a margin well below his previous landslide victories. But the large number of undecided voters gave late momentum to Capriles.

With Venezuela sitting on the world's largest oil reserves and Chávez a leading figure in the resurgence of the political left in Latin America, the vote will have an impact on the global economy, energy supplies and regional geopolitics.

But for most of the country's almost 19 million voters, the key concerns are the alarming rise in the murder rate, the redistribution of oil wealth, and the personality and health of the man who has led them for the past 13 years.

In the 23 de Enero neighbourhood where Chávez casts his vote, the strong revolutionary spirit is evident in elaborate wall murals depicting Karl Marx, the Paris communes, Fidel Castro and – of course – Hugo Chávez.

But the surge in murder and violent crime have tempted some voters here to consider alternatives. "My vote is a secret because the situation is quite difficult. There is a good candidate this year who has put up a fight against the president," said Plajeres Rangel, a 35-year-old hairdresser, who said security was one of her main concerns.

Commune leaders said Chavez maintained a solid core of support, but they acknowledged gains made by the Capriles campaign. "This area is strongly pro-Chávez, but the opposition has made inroads. They've been campaigning here for the first time and they've come out on to the streets, which they didn't do before," said José Roberto Duque, a journalist at a community radio station.

"I'm here with my family to share a stellar moment for Bolivian socialist democracy," said Noel Marquez, the director of a revolutionary music collective and composer of some of Castro's campaign jingles. "This is a country that is deeply committed to democracy. We have a trustworthy voting system, but the opposition have plans to distort things. They have created a climate of uncertainty, but the people will defend the vote."

On the eve of the vote, Chávez said he would accept any outcome and urged the opposition to do the same. "I call on all political actors from the left, right and centre for us to prepare emotionally to accept tomorrow's result. It won't be the end of the world for anybody," he said in a televised address .

Analysts fear a narrow win for either side could spark accusations of fraud and street violence. This has put the voting system under intense scrutiny, but it appears robust. External observers and domestic analysts have lauded the procedure as one of the most sophisticated in the world.

Presidential candidate Henrique Capriles has promised that he would maintain many of Chávez's social programmes. Photograph: Leo Ramirez/AFP/Getty Images

Voters first registered themselves by inputting their name, national identity number and thumbprint using a console. They then cast an electronic vote for their preferred party candidate on a touchscreen. Their vote entered the central counting system and was printed so that they could confirm it was recorded properly before that hard copy was put in a ballot box, more than half the contents of which would later be cross-checked with the electronic data to ensure the system had not been hacked.

Voters then had to sign a form to confirm they had cast a vote. Before they left, the little finger on their left hand was marked with indelible purple ink so they could not return to vote a second time. "This system is 100% fraud-proof and has been recognised as such by outside political institutions," said Luis Guillermo Piedra, of the National Electoral Council.

Former US president Jimmy Carter has described the system as superior to that of the US. His Carter Centre, based in Atlanta, Georgia, has noted that many Venezuelans are concerned a new electronic voting system might enable authorities to tell how they voted, exposing them to retaliation if they voted against Chávez. "This concern has no basis, however," the centre said. "The software of the voting machines guarantees the secrecy of the vote."

There is less certainty about what happens outside the voting booths. The opposition has lodged 110 complaints alleging abuses of election laws by the Chávez campaign, mostly relating to his domination of airtime on public broadcasting outlets and use of funds, staff and other resources from state-owned enterprises. They also feared that armed militias put pressure on voters before they went to the polls, though there have been no reports of this to date.

"I'll stay at home tonight to keep safe. If there is a close result, there might be trouble," said Jesus Gallardo, a shopkeeper who serves his customers through steel bars. He said he voted for Chávez, but added that he understands why the race has been tighter this time. "Many people are unhappy because of insecurity and failed promises."