Supporters of Portugal's centre-right government cheer after election results reveal their victory.
But the prospect of political uncertainty now looms, after results also showed a failure to win a parliamentary majority.
This year's general election served as a test of the government and Prime Minister Pedro Passos Coelho's tough austerity stance.
Victory for the government was unthinkable just a few months ago, with polls giving a solid lead to the Socialists.
It comes amid signs that voters elsewhere in Europe appear resigned to austerity.
Coalition supporter Ana Filomena said "After four years of great difficulties, work on recovery has begun, and we cannot go backwards and this team can take us forward."
A minority government could unnerve investors in the country -- not one has survived a full term since 1974 and the overthrow of the country's fascist regime.
Meanwhile, Socialist Party supporters were disappointed.
Leader Antonio Costa said he had failed to meet his goal of victory but would stay on the same track.
The general election was the first since Portugal exited an international bailout last year, and the economy returned to slow growth after a three-year recession.