Warsaw (AFP) - Poland's rightwing Prime Minister Mateusz Morawiecki on Monday congratulated his Hungarian counterpart Viktor Orban, Warsaw's closest ally in the EU, on winning a third straight term in a crushing electoral victory.

"The road to reform is never easy," Morawiecki tweeted, adding that "the support of the majority of society shows that it's worthwhile to make the effort."

"I wish you success, for Hungary and for Europe," said Morawiecki, leader of the Law and Justice (PiS) government which has cultivated close ties with Orban.

Poland and Hungary are allies in battles with EU institutions over their anti-migrant stance and drive for a more decentralised EU with greater powers for member states.

On a visit to Budapest Friday, Jaroslaw Kaczynski, leader of Poland's governing PiS party, also gave Orban his endorsement.

In his victory speech on Sunday night, Orban himself thanked Kaczynski for his support.

Poland's government has had its own run-ins with Brussels over its changes to the judicial system.

Orban's nationalist Fidesz party won around 49 percent of the vote, an improvement on its score from four years ago. The result may even gift Fidesz a two-thirds majority in parliament, which would enable it to change the constitution.