"We can say with clarity the Socialist party has won the elections," Jose Blanco, the party's secretary-general, said.
Zapatero told euphoric supporters outside the party's headquarters in Madrid that "the Spanish people have spoken clearly and decided to start a new era".
"I will govern with a firm but open hand."
Mariano Rajoy, the conservative candidate, told supporters in Madrid that he had "called the candidate of the Socialist party and wished him luck for the good of Spain".
|Voter turnout was high according to|
government figures [AFP]
Election campaigning was dominated by a flagging economy and concerns over immigration.
The poll was also jolted by a last-minute killing by suspected Basque separatists of Isaias Carrasco, a former municipal legislator.
The government said turnout on Sunday was high, but less than in 2004.
Spain's youth vote helped boost participation to 76 per cent in four years ago in outrage at what they saw as the then governing Popular Party's efforts to cover up who was responsible for election-eve bombings that left 191 people dead.
Zapatero, the then opposition leader, came from behind to win power on a wave of voter anger at the PP, which tried to blame the Eta Basque separatists for the bombings by Muslim radicals.
One of the key election issues has been the economy - one of Europe's great success stories with more than a decade of robust growth. But it is now cooling amid rising unemployment and high inflation.
Observers say that an end to a boom in the construction sector, the strongest engine of growth, is to blame.
Economists said growth could fall as low as 2 per cent this year - a rate not seen since the early 1990s - from more than 4 per cent a year ago as a global credit squeeze chokes Spain's already-cooling property sector.
The sector accounts for almost a fifth of Spain's GDP and jobs. Unemployment, which hit a 29-year low last year, is up by almost 300,000 since June to 2.3 million.
Highly indebted Spaniards, already struggling to meet higher mortgage repayments, are suffering from rising food and fuel prices that pushed inflation to a record 4.4 per cent in February.
Many are also unsettled by an unprecedented influx of more than three million registered immigrants in the past eight years - most of them from Morocco, Eastern Europe and Latin America.
Both main parties clashed over immigration, with the conservatives saying Zapatero, 47, had made Spain a magnet for destitute foreigners in search of a better life, draining resources for schools and health care.
Rajoy had vowed to make immigrants sign a contract obliging them to respect Spanish customs and learn the language. Zapatero's party called this position xenophobic.
In two heated election debates, Rajoy repeatedly accused Zapatero of lying about his dealings with Eta during and after failed peace talks in 2006.
The candidates also clashed on Zapatero's willingness to grant more self-rule to Spain's semi-autonomous regions.