WARSAW — Law and Justice leader Jarosław Kaczyński was pretty grumpy after Sunday's election, despite snap results showing that his party had easily swept to power for a second term.

He was right to be moody.

As the vote count trickled in over the course of Monday, it ended up showing that the opposition managed to narrowly take control of the 100-seat upper house, the senate.

Law and Justice (PiS) will form a government — it won 43.59 percent of the vote, giving it 235 seats, a majority of five in the 460-seat Sejm, the more powerful lower chamber. But Kaczyński now faces something new. For the first time in four years, the opposition controls an institution that could cause him problems in getting his agenda enacted.

But the old parliament isn't dead yet. In an unusual decision, it's being summoned for a two-day lame-duck session this week. That will allow PiS to deal with a host of tricky issues, including a law limiting the ability of local governments to block coal-mining projects.

Here are five takeaways from a more-interesting-than-expected Polish parliamentary election:

1. The senate suddenly gains in importance

The senate has long been ignored as a significant part of the legislature. But on Monday, when the opposition took control of 51 seats compared to 49 for PiS, Poles scrambled to figure out just what it can do.

The senate is less powerful than the Sejm. It can delay and amend legislation, but the Sejm can override such moves with an absolute majority. However, the senate also has a say in nominating many key officials, which will undermine PiS's attempts to put all government institutions under its control.

Assuming Law and Justice doesn't manage to lure over a couple of opposition senators — an emergency meeting was taking place in Kaczyński's office on Monday night — the senate will act as a brake on PiS. In the past four years, the party has faced no such obstacles, as it enjoyed an absolute majority in both chambers.

That led to the government racing through crucial legislation as bills with no committee scrutiny, late-night votes, and occasionally limiting opposition parliamentarians to 30-second speeches.

It will be much more difficult with an opposition-controlled upper house.

2. Politics gets more complicated

When PiS took power in 2015, the opposition was in shock. The centrist Civic Platform party, founded by European Council President Donald Tusk and which ruled Poland from 2007 to 2015, was in disarray. Its coalition partner, the Polish People's Party (PSL), barely scraped over the 5 percent threshold to take seats in parliament.

The left-wing Democratic Left Alliance (SLD) failed to win any seats at all and a couple of newly created parties, led by inexperienced leaders and filled with novice MPs, didn't provide much of a challenge to Kaczyński.

However, the makeup of the new parliament is much more difficult for him. Civic Platform — now the lead member of the Civic Coalition — is still the largest opposition party, taking 27.4 percent of the vote for 134 seats.

But the SLD is back as part of a larger grouping called the Left that took 12.56 percent for 49 seats. It plans to challenge PiS's right-wing policies by aiming to loosen Poland's restrictive abortion laws, weaken the role of the powerful Roman Catholic Church, and promote gay rights.

The Left also plans to push its own generous social welfare policies.

"Jarosław Kaczyński has a problem, because the Sejm will have a brave opposition that wants to fight," said Adrian Zandberg, leader of the Razem (Together) party that is part of the left-wing coalition.

PSL is back with 8.55 percent support, enough for 30 seats.

PiS also faces something new — a challenger on the right. That's something Kaczyński has long tried to avoid, but in this election, the Confederation, a grouping of ultra-nationalists, took 6.81 percent of the vote, giving it 11 seats.

3. Presidential election is the next big fight

President Andrzej Duda's five-year term expires in 2020, and all sides are gearing up for a bruising battle.

Duda was a surprise winner in 2015, as he'd been plucked from obscurity as an MEP by Kaczyński. But controlling the presidency was key to Kaczyński's radical reforms program — allowing him to take control of the judiciary and pass legislation with little fear of it getting vetoed.

Losing the presidency would be a disaster for PiS.

Tusk was long seen as the opposition's most viable presidential candidate, but that's no longer necessarily the case. Małgorzata Kidawa-Błońska, put forward as Civic Coalition's candidate for prime minister, is now being talked about as a presidential nominee.

She trounced Kaczyński in voting in Warsaw on Sunday — winning 408,766 votes to his 244,639. Tomasz Siemoniak, the deputy leader of Civic Platform, called her "the natural presidential candidate" in a radio interview, before adding that it all depends on if Tusk wants to jump back into Polish politics when his term as Council president ends in December.

But Duda won't be easy to beat. He's a good retail politician, devoting enormous time and energy to cultivating voters in the smaller towns and villages that form the core of PiS's support.

4. PiS will have a tougher time with the budget

PiS took power in 2015 at the height of a global economic boom. That allowed the party to carry out its generous social spending promises without destroying the country’s budget. It brought in child payments of 500 złoty (€115) a month, lowered the retirement age and scrapped income taxes for those under 26.

Despite that, next year’s budget is set to be the first in Polish history with no deficit.

A lot of that spending was covered by Poland's rapid economic growth and by closing tax loopholes — a method that the government is determined to stick to.

“We’re controlling public finances, we’ve radically improved their condition, and we’ll keep doing it,” Kaczyński said after the election.

Those programs helped cement voter loyalty, and the party made even more expensive promises this time around. It pledged extra pensions, lower social security payments for small companies, a boost in health care spending and to steeply increase the minimum wage.

But tougher times loom.

One of the main goals for PiS in the next term is to maintain the current levels of EU funds, and it rejects the current budget proposed by the European Commission. But with Brexit cuts and possible mechanisms to link subsidies to the rule of law, any increase in funds for Poland seems unlikely.

The external economic environment may also get much stormier. The trade wars unleashed by U.S. President Donald Trump are causing uncertainty, and growth in Western Europe is slowing sharply.

Few economists predict that Poland will fall into a recession, but even a slower pace of growth could cause big fiscal problems for PiS.

5. Continued friction with the EU

The PiS government's deep changes to the legal system frayed relations with the EU, prompting the Commission to file cases with the Court of Justice of the European Union. It also launched an Article 7 procedure against Poland for violating the bloc's democratic rules.

Ahead of the election, Kaczyński promised even deeper changes to the court system in the future. "If society trusts us, we will return to this," he said.

But the new political reality in Warsaw will make continuing the blistering pace of reforms much more difficult, something that could soothe relations with the EU.

There's been a change of tone on both sides.

Warsaw was thrilled that Frans Timmermans, the Dutch commissioner who was point-man on rule of law issues in the outgoing Commission, is moving on to be in charge of the European Green Deal. The Czech Republic's Věra Jourová will have the rule of law job in the new Commission, and she's called for dialogue with Hungary and Poland.

However, if that doesn't result in a change of policy, Jourová made clear that she'll be as much of an enforcer as Timmermans. "I will be firm on the principle. This is clear," she told the European Parliament during her confirmation hearing.

There's also growing pressure from net-paying countries to put tougher budgetary conditions on law-breaking members.

"It’s imperative to put into place the rule of law mechanism, ensuring the protection of the Union’s budget in case of generalized deficiencies in member states," said Johannes Hahn, the future budget commissioner.