Businessman Daniel Noboa, 35, will become the youngest president in Ecuador's history, after winning Sunday's run-off.
With more than 97% of votes counted, Mr Noboa, a centrist, had a lead of four percentage points over his left-wing rival, Luisa González.
Ms González conceded the election and congratulated Mr Noboa on his win.
In his victory speech, Mr Noboa said that he would "give back a smile and peace to the country".
The election campaign was overshadowed by unprecedented levels of violence, which saw one of the candidates, Fernando Villavicencio, assassinated just days before the first round of voting in August.
The murder rate in Ecuador quadrupled between 2018 and 2022 and opinion polls suggested that security was voters' main concern going into the election.
Flanked by heavily armed soldiers, Mr Noboa took to the stage and said that "tomorrow we will start working for a new Ecuador, to reconstruct a country battered by violence, by corruption and hate".
Analysts point out that Mr Noboa, who has little political experience, will face an uphill struggle to tackle Ecuador's security problem and its poorly performing economy during his limited time in office.
While presidential terms in Ecuador are normally four years long, this was an early election triggered by the dissolution of parliament by outgoing President Guillermo Lasso.
Mr Noboa will serve out the term begun by Mr Lasso, which will end in May 2025. He can then stand for a second term.
Supporters of the young businessman took to the streets to celebrate his win.
"We need new blood and not the old politics that have done us so much harm," a 23-year-old student told Reuters news agency. "Our president should waste no time and work very hard to put the brakes on insecurity."
During his campaign, Mr Noboa said that he would combat the country's powerful gangs - many of which operate from inside jail - by placing the most hardened criminals on prison ships off Ecuador's coast.
He has also said that he will boost security at Ecuador's borders and ports to disrupt key drug-trafficking routes.
In order to lift the economy from its post-pandemic slump, he has promised to increase employment opportunities for young Ecuadoreans, in particular by creating incentives for national and foreign companies.
A graduate of the Harvard Kennedy School, Daniel Noboa seems to have appealed to young voters fed up with a lack of prospects.
While he presented himself as an alternative to more established politicians, his critics point out that he comes from one of the most powerful families in Ecuador.
The young Noboa is the son and heir of banana magnate Álvaro Noboa, who tried - but failed - to be elected president five times.
His win is seen by many in Ecuador as a rebuke by voters to the Citizen Revolution Movement and its leader Rafael Correa.
Mr Correa, who governed Ecuador from 2007 to 2017 and has since been convicted over campaign irregularities, is living in exile in Belgium but continues to exert considerable influence on Ecuadorean politics.
Luisa González was Mr Correa's handpicked candidate and had promised to reinstate many of the social programmes her mentor had introduced during his time in office.
And while the 45-year-old lawyer had sailed to victory in the first round, she failed to gain enough new voters ahead of round two.
Some polls suggested that young voters in particular were tired of the divisive rhetoric used by Mr Correa and his party.
Following her defeat, however, Ms González struck a conciliatory note: "To those who didn't vote for us, I congratulate you because your candidate won, and as Ecuadoreans, I embrace them."
"This is democracy," she added.