Opposition parties have secured enough votes in Poland's general election to oust the ruling right-wing populist Law and Justice (PiS) party, results have confirmed.
PiS won the vote with 35.38%, ahead of Donald Tusk's centrist opposition Civic Coalition with 30.7%.
But Mr Tusk is now most likely to be able to form a broad coalition.
That would end eight years of rule under PiS leader Jaroslaw Kaczynski.
The final result of the count came from the National Election Commission on Tuesday.
Although the winning party is expected to be offered the chance to form a government, Mr Kaczynski will fall well short of the 231 seats he needs to form a majority in parliament.
"This is the end of the bad times, this is the end of the PiS government," Mr Tusk - a former president of the European Council - declared on Sunday night.
Mr Tusk could muster 248 seats in the 460-seat Sejm if he forms a government with the centre-right Third Way and New Left parties. Third Way was one of the big winners of the election, with 14.4% of the vote.
PiS has lost 41 seats since the last election and even if it did form a coalition with the far-right Confederation party, it would be 19 seats below the required number.
The opposition had already warned Poles it was their "last chance" to save democracy. The election commission put the turnout at 74.38% , the highest since the fall of communism in 1989.
After the results were officially confirmed, Mr Tusk said the "winning democratic parties" were in constant touch and ready to start governing at any time.
President Andrzej Duda, a Law and Justice ally, has until 14 November to convene parliament and is expected to give PiS the first chance of forming a coalition, even though it has very little chance of succeeding. The opposition leader called on him to make "energetic and quick decisions".
Warsaw Mayor Rafal Trzaskowski praised the "enormous power of civil society" after it emerged that 84.92% of the capital's 1.35 million registered voters had taken part.
Poland's stock market surged by more than 6% and its currency, the Zloty, also rose on the expectation of a new government.
Speaking after the exit poll on Sunday night, Mr Kaczynski warned voters he did not know if the party's "success will be able to be turned into another term in power".
International observers said on Monday that parties had been able to campaign freely before Sunday's vote, but PiS had enjoyed a "clear advantage" through biased state media coverage and the misuse of public funds.
State TV's election night coverage broadcast Mr Kaczynski's address to supporters in full, but gave little room to his main rival.
Although polls closed at 21:00 local time on Sunday, voters queued well into the night in Warsaw and Krakow, and into the early hours in Wroclaw.
Pollster Ipsos said the proportion of 18-29-year-old voters was bigger than those aged over 60.
Law and Justice came to power in 2015, and it has emphasised Catholic family values, increasing the minimum wage and raising child support and pensioner payments.
It also imposed a near-total ban on abortion in 2021 and has been accused of politicising the judiciary, by staffing top courts with judges sympathetic to the ruling party.
Mr Tusk has vowed to improve relations with the EU and unlock €36bn (£30bn) of EU Covid pandemic recovery funds frozen in a row over the PiS judicial reforms. His coalition has also vowed to liberalise abortion laws.
Poland has also been a staunch supporter of Ukraine since Russia's full-scale invasion last year and has taken in a million refugees.
PiS leaders did show signs of wavering in recent weeks, but that was seen as an attempt to court far-right voters and whoever leads the next government is expected to maintain Poland's support for its neighbour.
Poland may not get a new government before December, if President Duda does hand PiS the opportunity to try to form a government.
Assuming the PiS candidate chosen by the president fails to win a vote of confidence in parliament, the Sejm would then appoint a candidate who would also try to form a coalition and win a confidence vote.