Brazil's incumbent president Dilma Rousseff has won a second term, defeating her opposition rival Aecio Neves with a narrow margin in an election that largely split the country between the poor north and wealthier south.

Rousseff, the first woman president of the world's seventh-largest economy, took 51.6 percent of the vote to 48.4 percent for business favourite Neves in a run-off election.

The 66-year-old, a former leftist guerrilla who was jailed and tortured for fighting the 1964-1985 dictatorship, pledged to reconcile Brazil, reboot the economy and fight corruption after the victory of her Workers' Party (PT).

"This president is open to dialogue. This is the top priority of my second term," she told supporters in the capital Brasilia, clad in white alongside two-term predecessor Luiz Inacio Lula da Silva.

After four years of sluggish economic growth culminating in recession this year, she admitted her own report card had to improve.

"I want to be a much better president than I have been to date," she said, issuing "a call for peace and unity" after a bitter campaign of low blows and mutual recriminations.

Neves concedes defeat

Neves, who conceded defeat in a speech to his supporters, called Rousseff to congratulate her.

"I told her the priority should be to unite Brazil," he told disappointed supporters in Belo Horizonte, where he served two terms as governor of Minas Gerais state.

The race was widely seen as a referendum on 12 years of PT government, with voters weighing the party's landmark social gains against Neves's promise of economic revival.

The PT endeared itself to the masses with landmark social programmes that have lifted 40 million Brazilians from poverty, increased wages and brought unemployment to a record-low 4.9 percent.

But the outlook has darkened since Rousseff won election in 2010. She has presided over rising inflation amid protests against corruption, record spending on the World Cup and poor public services.

Rousseff led the first round earlier in October with 41.5 percent compared to 33.6 percent for Neves. Prominent environmentalist Marina Silva was in third place with just 21 percent of the votes.

ANALYSIS FROM OUR CORRESPONDENT

Gabriel Elizondo in Belo Horizonte

It was billed as one of the closest and most unpredictable elections of modern times, and it delivered. It was simply historic; an election political junkies in this country will be talking about for decades to come.

A few things stuck out for me:

In 2010, Rousseff won by 12 percent and 12 million votes. On Sunday, she won by 3 percent and 3.5 million votes, the narrowest presidential victory in Brazil’s history. The opposition PSDB party has made great strides in the past four year, as Neves defeated Rousseff by 6.8 million votes in important Sao Paulo state.

But the opposition failed to make inroads in the populace, economically growing northeast of the country.

Here’s a troubling number for you: In an election decided by 3.5 million votes, 37 million Brazilians either didn’t vote or voted for nobody. Perspective: That’s about two Canada’s.

If the opposition could have just got a fraction of those people to the polls on their side, they could have won easily. But they didn’t. They’ll have themselves to answer to on that. Likewise, Rousseff now finds herself governing a country that is largely shrugging its shoulders at her.

Give Rousseff credit, she was battered and bruised but managed to prevail sticking to her message focus on the poor and lower middle class. Victory in politics is all that matters, and she got it. Give Neves credit for coming so close. Just two months ago – an eternity in this country – there were rumours he’d drop out as he was polling so low. He's an opposition candidate, and mainstream and modern.

The opposition has a lot of good to take away from this election once they recover emotionally.

But Rousseff has the presidency, if not a mandate. Balancing both might be even more difficult than winning.

Follow Gabriel on Twitter