Police set up a cordon outside the Maritim Hotel, the venue of the party congress of Germany's right-wing populist Alternative for Germany (AfD) in Cologne on April 21, 2017

Germany's anti-immigration AfD handed its own leader a humiliating setback Saturday five months before a general election, as thousands of demonstrators rallied against its party congress.

The four-year-old Alternative for Germany has harnessed public anger over Chancellor Angela Merkel's decision to let in more than one million asylum seekers since 2015.

But its poll numbers have plunged in recent months as the influx waned, and amid a bitter power struggle between populists and more radical, hard-right forces.

That conflict spilled over at the weekend congress in the western city of Cologne, as delegates rejected a bid by co-leader Frauke Petry to adopt a more moderate-sounding "Realpolitik" programme intended to shut down the party's more extremist voices.

Top-selling daily Bild called delegates' decision to not even debate her motion a "crushing blow" for Petry, a 41-year-old former chemist who is pregnant with her fifth child.

Even as the gathering began, singing and chanting protesters attempted to stop delegates from entering the congress venue, a hotel in the city centre.

Some 4,000 police were dispatched to keep the peace, as two officers were injured in scuffles with violent demonstrators.

Thousands more held a peaceful rally for "diversity and tolerance" across town, while a bar across the street from the congress centre hung a large protest banner reading "No Koelsch for Nazis", referring to the local beer.

- 'Absurd immigration policies' -

In a fervent appeal opening the event, Petry said the AfD could still aim to become Germany's top party by the next general election in four years' time if it softened the harder edges of its message.

Members needed to decide "whether and how the AfD can become a realistic option to take power for voters by 2021 so we don't permanently leave the government to the established parties," she said.

The AfD, represented in 11 of Germany's 16 state legislatures, aims to sign off on a programme that will pave the way for the party to enter the national parliament this year for the first time.

It includes calls to stop family unification of refugees already in Germany, strip immigrants convicted of "significant crimes" of their German passports, and declare Islam incompatible with German culture.

The biggest applause at the congress went to Petry's co-leader Joerg Meuthen, who railed against the "absurd immigration policies" backed by both Merkel and her chief challenger, Social Democrats leader Martin Schulz.

"We don't want to become a minority in our own country," he said, vowing the AfD would campaign with "furious resolve" against its "tired political opponents".

All of Germany's mainstream parties have ruled out working with the AfD if it clears the five-percent hurdle to representation in the September 24 election.

Opinion polls show the party at between seven and 11 percent, a steep drop from the 15-percent support it drew only late last year.

Merkel is seeking a fourth term after nearly 12 years in power and her conservative Christian Democrats are currently leading the polls.

- Le Pen, Trump and Brexit -

The telegenic Petry has aligned herself with kindred spirits across Europe, including far-right firebrand Marine Le Pen, one of the frontrunners for the first round of the French presidential election on Sunday.

But analysts say there is little appetite among most Germans for radical change, particularly after the victories of Donald Trump in the United States and the Brexit camp in Britain.

Petry had made the shock announcement Wednesday that she would not seek to lead the AfD's campaign this year. The news left the party reeling and set the stage for the showdown between its warring factions.

Her chief rival, 76-year-old Alexander Gauland, a hardline defector from Merkel's CDU, had urged delegates to defeat her Realpolitik motion, calling it "divisive".

Denouncing "provocations" by party officials, Petry had also called for the ouster of an AfD state leader, Bjoern Hoecke, who in January sparked outrage by slamming Berlin's vast Holocaust memorial as a "monument of shame".

She claimed victory however on that point, as delegates defeated a motion to vote on whether he should be kept in the party.