A FAR-RIGHT former army captain has won the first round of Brazil’s presidential election by a surprisingly large margin, but fell just short of getting enough votes to avoid a second-round run-off against a leftist rival.

Jair Bolsonaro had 46% compared to 29% for former Sao Paulo Mayor Fernando Haddad, according to figures from Brazil’s Superior Electoral Tribunal with 99.9% of the vote counted. He needed over 50% support to win outright.

Polls predicted Bolsonaro would come out in front, but he far outperformed expectations, blazing past competitors with more financing, institutional backing of parties and free air time on television.

Ultimately, Bolsonaro’s strong showing shows a national yearning for Brazil’s past as much as a sign of the future.

The candidate from the tiny Social and Liberal Party made savvy use of Twitter and Facebook to spread his message that only he could end the corruption, crime and economic malaise that has seized Brazil in recent years.

“I voted against thievery and corruption,” said Mariana Prado, a 54-year-old human resources expert. “I know that everyone promises to end these two things, but I feel Bolsonaro is the only one can help end my anxieties.”

Bolsonaro has portrayed a country in collapse and advocated loosening gun laws so individuals can fight off criminals, giving police more powers to use force, and restoring “traditional” Brazilian values.

He capitalised on Brazilians’ deep anger with their traditional political class and “throw the bums out” rage after a corruption investigation revealed staggering levels of graft.

Beginning in 2014, prosecutors alleged Brazil’s government was run like a cartel for years, with billions of dollars in public contracts handed out in exchange for bribes.

The Workers’ Party was at the centre of that investigation, and it has struggled to make a comeback.

Haddad has promised to roll back President Michel Temer’s economic reforms that he says eroded workers’ rights, increase investment in social programmes and bring back the boom years Brazil experienced under his political mentor, Luiz Inacio Lula da Silva.

Though they come from opposite sides of the political spectrum, both Bolsonaro and Haddad ran campaigns based on nostalgia for a better time.

Bolsonaro evoked the country’s 1964-1985 military dictatorship amid promises of a return to traditional values and safer times.

In one of his last appeals to voters before Sunday’s voting, Bolsonaro tweeted he would “defend the family and the innocence of children, treat criminals as such and not get involved in corruption schemes”.

Bolsonaro’s poll numbers have increased by about 15% since he was stabbed on September 6.

He was unable to campaign or participate in debates as he underwent surgeries during a three-week hospital stay, but instead brought messages directly to voters via social media.

The campaign to run Latin America’s largest economy, which is a major trade partner for countries in the region and a diplomatic heavyweight, has been unpredictable and tense.

The stabbing forced candidates, and Bolsonaro himself, to shift strategies and recalibrate.

This election was once seen as the great hope for ending a turbulent era in which politicians and business executives were jailed on corruption charges, a president was impeached and removed from office, and the region’s largest economy suffered a protracted recession.

But caught in the middle are Brazilians who dislike both candidates and see them as symbols of a broken system.

“I think we’re going to continue with the same polarisation,” if either Haddad or Bolsonaro wins, said Victor Aversa, a 27-year-old massage therapist who voted for centre-left candidate Ciro Gomes, who had been polling third.