By Marek Strzelecki and Anna Wlodarczak-Semczuk
WARSAW (Reuters) - Poland's incumbent Law and Justice (PiS) have won the most votes for a single party in Sunday's general election, exit polls showed, but the liberal opposition bloc of parties appeared to secure a parliamentary majority, raising the possibility of an end to eight years of nationalist rule.
If the outcome is confirmed by official results, the vote would mark a massive turnaround for Warsaw, which has feuded with the European Union over the rule of law, media freedom, migration and LGBT rights since PiS came to power in 2015.
With war raging in neighbouring Ukraine and a migrant crisis brewing, Brussels and Washington have been watching the vote closely, although both PiS and its mainstream opposition support NATO-member Poland's key role in providing military and logistical support to Kyiv.
The Ipsos exit poll gave PiS 36.8% of the vote, which would translate into 200 lawmakers in the 460-seat parliament
Opposition parties, led by the liberal Civic Coalition (KO), were projected to together win 248 seats, with the KO seen winning 31.6% of ballots cast.
The late exit poll was delayed, with some commentators saying that it was due to the unexpected record turnout.
Partial official results were due to be published on Monday. By 5:30 a.m. (0330 GMT), only about 3.6% of the votes were counted, according to the electorate commission.
Television footage showed several hundred people, mostly young, waiting in a long line at one polling station in the western city of Wrocław to vote. Local residents were bringing them hot tea and blankets as well as some food.
Some of those in line said they waited for six hours. The polling station closed just before 3 a.m. (0100 GMT), some six hours after the voting stations were set to officially to close.
KO leader Donald Tusk, 66, a former European Council president, has vowed to mend Warsaw's relations with Brussels, undo PiS reforms and hold its leaders to account.
"Democracy has won ... This is the end of the PiS government," a jubilant Tusk told party members on Sunday evening.
If official results confirm the exit poll, Tusk and his allies from the centre-right Third Way and the New Left may have to wait weeks or even months before getting a turn at forming a government.
President Andrzej Duda, a PiS ally, has said he would give the first shot to the winning party, suggesting Prime Minister Mateusz Morawiecki or another party leader would have the chance first. But with the far-right Confederation scoring 6.2%, below expectations, he will have few obvious allies, experts said.
"We are facing an intense few weeks," said Anna Materska-Sosnowska, a political scientist from the Warsaw University.
RECORD TURNOUT
In addition to its democratic record, which critics say had put Poland on a path towards authoritarian rule, PiS is accused of deeply polarising Poland.
Seeking an unprecedented third term, PiS had cast the vote as a choice between security from unfettered migration, which it says its opponents support, and a creeping Westernisation it sees as contrary to Poland's Catholic character.
Reflecting mounting discontent in the former Soviet bloc country over democratic backsliding and an erosion of women's rights on one hand and the cost of living on the other, turnout appeared to reach the highest level since the collapse of communism in 1989.
Many voters from Warsaw, where KO usually wins, travelled to PiS-supporting towns outside the capital to cast votes. Broadcasters showed long queues still forming outside some voting stations even after the election had officially ended.
PiS leader Jaroslaw Kaczynski, 74, told officials gathered at the party's headquarters in central Warsaw that it was not clear whether Sunday's showing would translate into a new term in office.
"We have to have hope that regardless of whether we are in power or in opposition, our project will continue ... We will not let Poland lose ... the right to decide its own fate."
PiS, which denies eroding democratic standards, says its reforms aimed to make the country and its economy more fair while removing the last vestiges of communism. It has built its support on generous social handouts and a pledge of more independence from Brussels.
Tusk has said he would seek to unblock some 110 billion euros of EU funds earmarked for Poland which have been frozen due to rule-of-law concerns, from day one if he heads a new government.
However, EU officials say it is unlikely to be so simple as changes to any laws pushed through by PiS would still require the signature of President Andrzej Duda, a PiS ally.