(Adds detail from Rousseff's speech)
By Brian Winter and Anthony Boadle
SAO PAULO/BRASILIA, Oct 26 (Reuters) - Brazil's leftist President Dilma Rousseff narrowly won re-election on Sunday after convincing voters that her party's strong record of reducing poverty over the last 12 years was more important than an ongoing economic slump.
After the closest, most divisive campaign since Brazil returned to democracy three decades ago, Rousseff won 51.6 percent of votes in a runoff against centrist opposition leader Aecio Neves, who won 48.4 percent support.
The vote split Latin America's biggest country almost evenly in two along lines of both social class and geography. Neves prevailed in Brazil's richer south, southeast and center-west, while Rousseff took the Amazon north and impoverished northeast.
Voting was peaceful and Brazil's robust democracy is free of the political violence that mars some other countries in the region. Yet, mindful of the deep economic challenges facing the country, both Neves and Rousseff sounded a cautious, conciliatory tone in speeches on Sunday night.
"I call on all Brazilians, without exceptions, to unite in favor of Brazil's future," Rousseff, her voice hoarse after weeks of campaigning, told a raucous crowd of party supporters gathered at a hotel in Brasilia. "I want to be a much better president than I have been until now."
However, she gave no clear indication of any impending changes to the heavy-handed economic policies that have alienated many investors since she took office in 2011, limiting herself to a pledge to seek to restore growth.
The result means another four years in power for the Workers' Party, which since 2003 has virtually transformed Brazil - lifting 40 million from poverty, reducing unemployment to record lows and making big inroads against hunger in what remains one of the world's most unequal countries.
The party's star has faded recently. The economy has averaged less than 2 percent annual growth under Rousseff's often unpredictable policies, making Brazil's glory days of robust growth last decade an ever-more distant memory.
Numerous corruption scandals, high inflation and frustration over poor public services like health care tempted many to consider a switch to Neves' more pro-business agenda.
Yet Rousseff and her supporters spent the campaign warning voters, especially the poor, that a vote for the PSDB would mean a return to the less compassionate, more unequal Brazil of the 1990s - an argument that Neves rigorously denied, but ultimately prevailed anyway.
"We need Dilma to continue the programs that improve the lives of those in need," said Livia Roma, 19, a university student in Sao Paulo, as she voted on Sunday. "I didn't vote for myself, but for the minorities and less fortunate classes."
Brazil's financial markets plummeted last week when polls showed Rousseff was likely to win a second term. They could see another selloff on Monday.
With 200 million people and a gross domestic product of some $2 trillion, Brazil is Latin America's largest economy and its most populous country.
By re-electing Rousseff, Brazil will remain on a middle ground between more socialist governments in Venezuela and Argentina, and the freer-trading, faster-growing countries on the Pacific coast that include Colombia and Chile.
Rousseff owed her victory to overwhelming support from the roughly 40 percent of Brazilians who live in households earning less than $700 a month.
They have benefited from the Workers' Party's rollout of a program that pays a small monthly stipend to one in four Brazilian families, as well as federal housing programs, government-sponsored vocational schools and an expansion of credit to the working class.
Rousseff, 66, is unlikely to enjoy much, if any, of a honeymoon when her second term starts on New Year's Day.
Recent allegations of systemic corruption at state-run oil giant Petrobras roiled the final days of the campaign and are likely to be a major political headache in coming months and years as prosecutors pursue those responsible.
The economy slipped into a recession earlier this year, and ratings agencies have warned that a credit downgrade is possible unless Rousseff makes hefty spending cuts to correct deficits that have mushroomed in recent months.
Her aides have said she will try to win back the confidence of financial markets by announcing a more pragmatic finance minister for her second term, although many investors worry that Rousseff will continue to call most of the shots herself.
Marco Aurelio Garcia, a top Rousseff adviser on foreign affairs, sounded a defiant note shortly after the results were published. Asked what the government's message to financial markets was, he replied: "Take tranquilizers."
The campaign was one of the most dramatic in Brazil since direct elections were restored in 1989. One candidate was killed in a plane crash in August, and his replacement then soared into the lead in opinion polls, only to fade in the final days before the first round of voting Oct. 5.
During the runoff, senior leaders from both parties compared their rivals to Nazis - a break from the relatively genteel tone that has prevailed in Brazilian politics in recent years, and one that analysts say heralds a more divisive era ahead.
That, in turn, may make consensus on a much-needed overhaul of the tax code and other economic reforms more difficult for Rousseff to push through.
Rousseff, who was jailed and tortured in the early 1970s for opposing that era's military dictatorship, is the country's first woman president. The daughter of a Bulgarian aristocrat who emigrated to Brazil during World War Two, she was a relatively obscure government technocrat until her predecessor Luiz Inacio Lula da Silva hand-picked her as his successor.
Many in the Workers' Party are already thinking ahead to the next election in 2018, when Lula, who governed from 2003 to 2010, has said he may run again. Brazil's constitution doesn't allow presidents to seek a third consecutive term.
Rousseff repeatedly thanked Lula for his support on Sunday night, and gave him a big hug onstage.
Neves' PSDB, meanwhile, faces an uncertain future after falling short in three straight presidential contests due in part to its image as the party of Brazil's wealthy minority.
The PSDB is under added pressure because of a long drought in Sao Paulo state, which it governs, that has raised the prospect of severe water rationing in coming months.
"Our biggest priority should be to unite Brazil," Neves said in his concession speech, noting that he had called Rousseff and wished her success. (Additional reporting by Alonso Soto; Editing by Todd Benson and Kieran Murray)