Budapest (AFP) - Turkish President Recep Tayyip Erdogan was given a warm welcome in Hungary Monday just weeks after Ankara's strained relations with other EU nations were thrown into sharp relief in a tense visit to Germany.

The Turkish leader has had staunch support from Budapest even as EU relations waver, with Prime Minister Viktor Orban among the first to congratulate Erdogan on his re-election in July and one of the few European officials to attend the inauguration ceremony in Ankara.

A fierce critic of what he sees as an undemocratic Europe, Orban has repeatedly hailed the "stability" that he perceives the Turkish regime offers.

"Turkey's stability is the guaranty of our security," he said at a joint press conference with Erdogan, referring to the role of Turkish authorities in controlling migration into Europe.

He urged Europe to put in place a "strategic cooperation with Turkey, at all costs".

The visit comes after a sensitive trip to Germany at the end of September, as Berlin and Ankara face the daunting task of rebuilding relations and trust battered by a succession of disputes.

Turkey's relations with Germany -- and other key EU states -- had hit historic lows in the aftermath of the 2016 failed coup to oust Erdogan as Berlin took issue with the scope of the remorseless crackdown afterwards that also caught up German nationals.

Ankara needs the EU as relations with the United States deteriorate and the Turkish economy, very dependent on trade with Europe, is in difficulty.

Erdogan's two-day visit to Hungary will also allow him to show his critics that "no, the EU hasn't completely turned its back on Turkey," said Tamas Szigetvari, economics professor at Peter Pazmany University in Budapest.

"It's nice for him to visit an EU country where he isn't under fire for his record on human rights and democracy," the expert told AFP.

- Turkey's 'cousins' -

The Turkish leader and the Hungarian premier, who secured his third consecutive term in office in April, are perceived to be made of the same mettle -- democratically elected but with authoritarian and distinctly anti-liberal tendencies.

Story continues

Restrictions on freedom of expression in Turkey have come in for sharp international criticism, while Hungary risks sanctions from the EU over legislative changes seen as a threat to the rule of law and the bloc's values.

Relations between Hungary and Turkey may currently be cordial, but the two countries' history has not always been so friendly, and Hungary was occupied by the Ottoman empire for a century and a half between 1541 and 1699.

Nowadays, Erdogan professes nostalgia for the Ottoman empire, while Orban's government promotes so-called "turanist" theories, hotly disputed by historians and linguists, that see Turkish and Finno-Ugric languages, including Hungarian, as sharing a common origin.

On a visit to Kyrgyzstan in September, Orban lauded Hungarian as a "strange and unique language related to Turkish languages".

Tamas Szigetvari argues that such theories enable Orban to portray Hungary as a sort of distant cousin to countries in Asia that Budapest is wooing for economic reasons.

But not everyone is happy about the cordial relations between the two countries: a small centre-left party said that a demonstration it had been planning to protest Erdogan's visit has been banned under a new law that came into force this month that restricts freedom of assembly.