The conservative challenger in Poland's presidential election, Andrzej Duda, has defeated the incumbent, Bronislaw Komorowski, final results show.
Mr Duda won 51.5% of votes in the run-off, while Mr Komorowski polled 48.5%.
Mr Duda had edged Mr Komorowski, who had been the favourite, in the first round but did not gain the 50% needed to win outright.
The president has limited powers, but is head of the armed forces and can veto new laws.
The victory will be a wake-up call to Prime Minister Ewa Kopacz, an ally of Mr Komorowski, ahead of parliamentary elections this autumn.
Mr Komorowski conceded victory earlier, as exit polls were announced.
"I respect your choice," he said, addressing voters. "I wish my challenger a successful presidency."
Speaking to supporters in Warsaw, Mr Duda said: "Thank you President Bronislaw Komorowski for the rivalry of this presidential campaign and for your congratulations.
"Those who voted for me voted for change. Together we can change Poland."
Analysis: BBC's Adam Easton in Warsaw
This is a remarkable and decisive victory for Mr Duda. It's remarkable because he is a relative unknown and Mr Komorowski has been a popular president. It suggests that many Poles have grown weary of President Komorowski's backers, the governing centre-right Civic Platform party.
In its eight years in office the party has maintained Poland's economic growth despite the financial crisis. But it has also reneged on some of its promises and increased the retirement age, an unpopular move.
Poland is gradually catching up to Western Europe's living standards but youth unemployment is high and Poles can still earn much more in the UK or Germany. Many Poles simply do not feel the benefit of 25 years of near uninterrupted growth and Mr Duda appeals to them.
He has promised to bring the retirement age back down, but he'd need his Law and Justice party to win this autumn's parliamentary elections to be able to do that. It's been 10 years since they won an election but many think that may now happen. If it does, judging by its last spell in office in 2005-2007, Poland will become more inward looking and much less at ease with its EU partners.
Mr Komorowski, 62, took office five years ago after his predecessor, Lech Kaczynski, died in a plane crash.
He had been the favourite according to earlier opinion polls, and had been looking for a second term.
Mr Duda, 43, is from the right-wing opposition Law and Justice party, which is led by former President Kaczynski's twin brother, Jaroslaw.
In the first round, Mr Duda attracted most support in the more conservative eastern regions of the country, near the border with Ukraine and Belarus.