WARSAW — Poland's nationalist Law and Justice (PiS) party won Sunday's parliamentary election, taking 43.76 percent of the vote, according to a count of 99.4 percent of the votes cast on Monday.

However, the party appears to have lost control of the upper house, the senate, and is looking like taking 49 seats to 51 for the opposition; in most districts, opposition parties united around a single candidate.

The senate is less powerful than the lower chamber, the Sejm, but it can slow the passage of legislation and appoint key officials — for the first time in four years complicating PiS's control of the legislature.

PiS was far ahead of the main opposition party, Civic Coalition, which took 27.24 percent. Further behind was the Left, a grouping of left-wing parties, with 12.52 percent, the conservative Polish Coalition with 8.58 percent, and the right-wing Confederation party with 6.79 percent.

That vote total appears to give PiS control of the 460-seat Sejm, but a final seat allocation has not yet been calculated.

Kaczyński complained about "this huge front against us" and lamented that there are still many voters who don't support PiS.

There is little doubt that PiS will be able to form the next government, but it won't have the same free rein it has enjoyed since 2015.

Four years ago, with an absolute majority in both the Sejm and the senate, as well as the country's presidency, PiS was able to push through deep reforms of the court system that occasionally violated the constitution and set off an ongoing fight with the European Commission. It also turned state television and radio into propaganda arms of the ruling party, replaced most of the top jobs in state-controlled companies, and was able to rush legislation through parliament with very little effective resistance from the opposition.

In recent months, PiS has tried to ease the conflict with Brussels. The party supported Ursula von der Leyen as Commission president, and was thrilled that Frans Timmermans will be shifted away from enforcing the EU’s democratic principles to being in charge of the European Green Deal in the new Commission.

During the campaign, Jarosław Kaczyński, the party's leader and the country's de facto ruler, rejoiced that Janusz Wojciechowski will be the new agriculture commissioner, calling it one of the most important posts in the Commission and one with key meaning for Poland.

For more polling data from across Europe visit POLITICO Poll of Polls.

Warsaw wants to strengthen its position during the ongoing negotiations over the EU’s future budget, fearing a dramatic cut in the funds currently flowing from Brussels.

Despite winning a second term in office, the tone at PiS's party headquarters in downtown Warsaw was far from euphoric on Sunday night.

Kaczyński complained about "this huge front against us" and lamented that there are still many voters who don't support PiS.

"We received a lot, but we deserve more," he said as party supporters chanted his name. "This means an obligation for us, an obligation for more work, more ideas, looking at the groups that didn't support us. We'll have to consider a lot of things."

He came back to the stage after a few minutes to again bask in the cheers and complained that there are some voters who feel that the opposition would do a better job of managing the economy than PiS, calling such thoughts "idiotic."

He was echoed by Prime Minister Mateusz Morawiecki, who said that "the wind was in our eyes for four years. We had a twisting uphill road."

Disappointed opposition

Voter turnout was 61.1 percent, the highest in three decades — a sign of the deep divisions in the country after four years of a PiS government. Each party tried to galvanize its voters by warning that a victory by its rivals would be a disaster for the country. The exit polls indicated a country split almost equally in two.

"Polish society is very, very deeply divided," former President Aleksander Kwaśniewski told Poland's TVN24 news channel.

The results were a blow to the leading opposition Civic Coalition. Its leading party, Civic Platform, founded by European Council President Donald Tusk, ruled Poland from 2007 to 2015.

"There were no rules. We didn’t have a feeling this was an honest fight, that these were fair elections," said party leader Grzegorz Schetyna.

The surprise of the night was Confederation, a far-right grouping led by perpetual political gadfly and former MEP Janusz Korwin-Mikke.

Smaller opposition parties were much happier with the outcome.

The Left failed to win seats in 2015 because several smaller parties split the left-wing vote and failed to make it over the threshold needed to win seats.

"We’re returning to the parliament!” shouted Robert Biedroń, leader of the Wiosna (Spring) party, and an MEP. “We’ll be a constructive opposition in parliament, we’ll defend the constitution from its first to its last article.”

The Polish Coalition, led by the Polish People's Party, the country's oldest political grouping, was very pleased that it easily passed the 5 percent threshold to win seats.

The surprise of the night was Confederation, a far-right grouping led by perpetual political gadfly and former MEP Janusz Korwin-Mikke.

The opposition vowed that the political battle would continue despite being disappointed by the outcome.

"There are elections ahead of us, the presidential vote [in 2020], and we will win, that’s our promise," Schetyna said.

This article has been updated with updated vote count results and results for the senate.