With most of the votes counted in the second round of Peru's election, it has become clear that ex-president Alan Garcia has won a convincing victory.
Garcia greets supporters celebrating his remarkable comeback
Mr Garcia polled 53.1% of ballots to 46.9 % for nationalist rival Ollanta Humala, with 93% of votes counted.
The two men had fought a fierce and aggressive campaign.
Mr Garcia, who served for five turbulent years from 1985-1990, told cheering supporters: "We thank the people of Peru."
He said the result was a blow for Venezuelan President Hugo Chavez, who had strongly supported his opponent.
"Today, the majority of the country has delivered a message in favour of national independence, of national sovereignty," he said.
"...They have defeated the efforts by Mr Hugo Chavez to integrate us into his militaristic and backwards expansion project he intends to impose over South America. Today, Peru has said no."
The Venezuelan deputy foreign minister said Mr Garcia's election would not bring about an immediate change in bilateral relations.
The two countries withdrew their ambassadors last month amid recriminations over Mr Chavez's alleged meddling in the election.
Mr Humala accepted defeat but said his nationalist project had secured "an historic political and social victory".
US Deputy Secretary of State Robert Zoellick said Washington was looking forward "to working with president-elect [Alan] Garcia".
"The best response is that of the Peruvian people (who) decided to vote for President Garcia and not for [Hugo] Chavez's candidate," Mr Zoellick said.
For weeks, Mr Garcia and Mr Humala vying to be president had traded insults and allegations.
Mr Garcia tried to portray Mr Humala as a dangerous threat to democracy and peace, while Mr Humala reminded Peruvians of the mistakes of Mr Garcia's presidency, which was marked by rebel attacks and rampant inflation.
Ollanta Humala went jogging before casting his vote
Mr Garcia won majorities in the capital, Lima, and along the more developed northern coast, but Mr Humala polled well in the southern and central areas.
The BBC's Daniel Schweimler in Lima says Mr Garcia's biggest challenge now is to unite a politically divided country.
The new president acknowledged the challenges ahead as he greeted cheering supporters at the headquarters of his Apra party in Lima.
"We must think this night of all of our past errors, about all our defects and make an act of contrition," Mr Garcia told supporters gathered at the headquarters of his Apra party.
No-one had been defeated, he said, and promised to work to ensure development in the impoverished south of the country, Mr Humala's heartland.
During the campaign, Mr Garcia frequently referred to the former army officer's involvement in an armed uprising, and criticised his lack of political experience and close ties to Mr Chavez.