Portugal's governing centre-right coalition has won the country's general election, which was widely seen as a referendum on four years of austerity.
Socialist leader Antonio Costa admitted defeat and congratulated Prime Minister Pedro Passos Coelho.
With almost all votes counted, the centre-right leads with just under 37%, with the Socialists on over 32%.
However, Mr Passos Coelho said his coalition appeared to have lost its absolute majority in parliament.
With 99 seats in the 230-seat parliament, the ruling coalition fell 17 seats short of the number it needed.
Mr Passos Coelho indicated that he was ready to talk to other parties in the next parliament to pursue the "necessary reforms" he wants to implement.
"Times haven't been easy, and the times ahead will be challenging," he said, promising to talk to the Socialists with the aim of maintaining a rigorous budget and a reduction in the public debt.
Parties to the left of the Socialists achieved their best-ever result, says the BBC's Alison Roberts in Lisbon.
Left Bloc won 10% of the vote, securing 19 seats, while the Communists took 8% of the vote.
Four years of austerity have taken their toll, and the coalition lost almost one-third of the votes that its two constituent parties gleaned in the last general election, our correspondent adds.
The coalition had vowed to continue the policies in place since 2011, after Portugal's caretaker Prime Minister Jose Socrates was forced to seek a eurozone bailout.
Unemployment has been falling for two-and-a-half years, but many regard the recovery as fragile.