(Adds call from Trump, comments from supporter, economic adviser, market reaction)
By Anthony Boadle and Gabriel Stargardter
BRASILIA/RIO DE JANEIRO, Oct 28 (Reuters) - Far-right lawmaker Jair Bolsonaro won Brazil's presidential election on Sunday, promising to clean up politics, shrink the state and crack down on crime, in a dramatic swing away from the left in the world's fourth-largest democracy.
The former army captain has alarmed many with vows to sweep political opponents off the map and comments denigrating women, gays and racial minorities.
He will be the first president with a background in the armed forces since the end of Brazil's 1964-1985 military dictatorship, which he has publicly praised. He has tapped retired generals to serve as his vice president and run key ministries.
In his first public comments after his landslide victory, he pledged to respect democratic principles, but said he wanted to change the country's direction.
"We cannot continue flirting with socialism, communism, populism and leftist extremism ... We are going to change the destiny of Brazil," Bolsonaro said in an acceptance address, promising to root out graft and stem a tide of violent crime.
An outspoken admirer of U.S. President Donald Trump, Bolsonaro also pledged to realign Brazil with more advanced economies rather than regional allies, overhauling diplomatic priorities after nearly a decade and a half of leftist rule.
Trump called Bolsonaro to wish him good luck soon after his electoral victory, auguring closer political ties between the two largest nations in the Americas — both now led by conservative populists promising to overturn the political establishment.
Bolsonaro won 55.2 percent of votes in the run-off election against left-wing hopeful Fernando Haddad of the Workers Party (PT)'s 44.8 percent, according to electoral authority TSE.
The 63-year-old congressman's rise has been propelled by rejection of the leftist PT that ran Brazil for 13 of the last 15 years. The party was ousted from power in 2016 in the midst of a deep recession and political graft scandal.
Thousands of Bolsonaro supporters cheered and set off fireworks outside his home in Rio de Janeiro's luxurious beachfront Barra de Tijuca neighborhood as his victory was announced. In Brazil's commercial capital of Sao Paulo, Bolsonaro's win was greeted with fireworks and the honking of car horns.
Investors have also cheered Bolsonaro's ascent, relieved that he could keep the PT out of power and hopeful that he would carry out fiscal reforms proposed by his orthodox economic guru.
Tokyo-listed Brazilian stock exchange traded funds (ETFs) jumped more than 12 percent when Japanese markets opened following Bolsonaro's win.
"I don't idolize Bolsonaro and I don't know if he will govern well, but we are hopeful. People want the PT out, they can't take any more corruption," said Tatiana Cunha, a 39-year-old systems analyst in the midst of the noisy celebrations in Rio.
Many Brazilians are concerned that Bolsonaro, an admirer of the dictatorship and a defender of its use of torture on leftist opponents, will trample on human rights, curtail civil liberties and muzzle freedom of speech.
Human Rights Watch called on Brazilian judges, prosecutors, media and civil society to stand up against any attempt by Bolsonaro to "erode the democratic rights and institutions Brazil has painstakingly built in the last three decades."
In his acceptance speech, Bolsonaro promised to govern according to the Bible and the country's constitution.
The live broadcast of Bolsonaro's words was preceded by a prayer led by lawmaker, pastor and gospel singer Magno Malta, underscoring Bolsonaro's ties to evangelical churches that backed him for supporting their conservative social agenda.
Brazil's rapidly expanding evangelical congregations have created a conservative political force, which Bolsonaro tapped into by decrying sex education in schools and pushing back against gay rights.
He has vowed to crack down on crime in Brazil's cities and farm belt by granting police more autonomy to shoot suspected criminals. He also wants to let more Brazilians buy weapons to fight crime.
He himself was stabbed at a rally last month and will need to undergo surgery in mid-December to remove a colostomy bag, the head of his right-wing Social Liberal Party Gustavo Bebianno told reporters.
Bolsonaro said he would "unite Brazil" by cutting bureaucracy and red tape for businesses. He said he was committed to fiscal discipline and called for the early elimination of the federal government's budget deficit.
"We are going to think in terms of more Brazil and less Brasilia," he said, referring to the nation's capital where he will take office on Jan. 1.
Financial markets are expected to rally on Monday on Bolsonaro's victory.
The real currency has gained about 10 percent against the dollar in the last month as Bolsonaro's prospects of winning increased. Sao Paulo's benchmark Bovespa stock index has risen 13.5 percent since mid-September.
Investors are particularly heartened by his choice of Paulo Guedes, a Chicago University-trained economist and investment banker, as his economic guru and future economy minister.
Guedes said the new government will try to erase Brazil's unsustainable budget within a year, simplify and reduce taxes, and create 10 million jobs by cutting payroll taxes. New rules will boost investment in infrastructure, he told reporters.
Guedes is keen to privatize an array of state enterprises, including units of oil company Petroleo Brasileiro SA (Petrobras) and power utility Centrais Eletricas Brasileiras SA (Eletrobras).
However, his free-market ideas have clashed with the views of the retired army generals who are helping Bolsonaro flesh out his government program.
On Sunday, Guedes said Brazil would seek to improve trade relations outside the restrictions of the Mercosur bloc founded with neighboring Argentina, Uruguay and Paraguay.
Bolsonaro's rise follows conservative electoral victories in Argentina, Chile, Colombia, Paraguay, and Peru, pushing the continent to the right and undermining support for the authoritarian socialist regime in Venezuela.
Several hundred PT demonstrators protested Bolsonaro's victory on Sao Paulo's main Paulista Avenue before police dispersed them using tear gas.
But voting was calm and orderly across the country, said Laura Chinchilla, the former president of Costa Rica who is head of the Organization of American States' Electoral Observation Mission. Brazil has suffered a spate of partisan violence during the polarized campaign.
Reporting by Anthony Boadle and Jake Spring in Brasilia, Gabriel Stargardter and Rodrigo Viga Gaier in Rio de Janeiro and Brad Brooks in Sao Paulo; Editing by Brad Haynes, Daniel Flynn and Rosalba O'Brien