The favourite to win, Oscar Arias, a Nobel Peace laureate and former president, is facing a strong challenge from Otton Solis of the Citzen's Action Party, defying opinion polls prior to voting that predicted Solis would receive less than a quarter of the vote.
With 78% of the votes counted on Monday, Arias, of the centre-right National Liberation Party, had 40.7% support compared to 40% for Solis.
Costa Rica's electoral tribunal temporarily suspended the vote count to allow officials to rest.
The winner will need at least 40% of the votes to win outright and avoid a second round of voting in April.
The candidates and, it seems, voters are divided over the country's potential participation in the Central American Free Trade Agreement (Cafta) with the US.
Costa Rica is the only country in the region yet to sign up.
Solis, a 51 year-old economist, maintains the agreement would bankrupt small-scale Costa Rican farmers and should be re-negotiated.
Arias, hailing from a wealthy coffee farming family, argues it would revitalise the country's stagnant economy.
Arias won the Nobel Peace Prize
in 1987 as Costa Rica president
As officials concluded counting votes for the night, Arias emerged from his room at a San Jose hotel to thank dozens of supporters who had waited for hours for him to speak.
"We'll have to be respectful of our democratic institutions and postpone the celebration of our irreversible triumph for another 24 hours," he said. "We didn't expect such a tight race."
Under Costa Rican law, the president - Abel Pacheco of the Social Christian Unity Party - cannot seek immediate re-election.
But the Constitutional Court ruled in 2003 that former presidents could run again after leaving office and sitting out at least one four-year term, a loophole allowing Arias to run.
He won the 1987 Nobel Peace Prize for working to end Central America's civil wars while serving as president between 1986-90.
Analysts said the surprising results could be because of the large number of undecided voters. A poll published last week showed 20% of voters had not made up their minds three days before the election.
Plea for calm
"The polls never told the truth," Solis said. "We said it many times."
He asked his supporters, who were gathering at his party's headquarters, to stay calm and wait for complete results.
Solis lost the race for the presidency four years ago having founded the Citizen's Action in 2001 after leaving the National Liberation Party.
Twelve other candidates also were vying for the presidency in an election that officials said had a 66% turnout - the lowest in Costa Rican history.
Supporters will have to wait a
little longer for the result
Costa Ricans traditionally have treated presidential elections as a national holiday, and the country has had the region's highest voter turnout.
But in the streets of San Jose, the country's capital, few houses displayed posters of the candidates before Sunday's vote and only a handful of cars carried party flags.
Indifference to the election stems from a string of alleged scandals involving three former presidents.
Costa Ricans were also choosing all 57 members of congress, two vice presidents and dozens of city councilors.