BERLIN (Reuters) - A German court banned the domestic spy agency from classifying the Alternative for Germany (AfD) as a “case to investigate”, handing a symbolic victory to the far-right party before five important elections later this year.

FILE PHOTO: Alice Weidel and Alexander Gauland of Alternative for Germany (AfD) attend a session of Germany's Bundestag (lower house of parliament) in Berlin, November 21, 2018. REUTERS/Fabrizio Bensch/File Photo

The AfD has been ostracized by political opponents despite being the biggest opposition party in parliament after gaining seats there in the 2017 election. Other parties have rejected coalitions with the AfD at national or regional level.

In January, domestic intelligence (BfV) chief Thomas Haldenwang said his agency had classified the anti-immigrant AfD as a “case to investigate”.

On Tuesday, the Cologne administrative court ruled that the BfV had failed to legally justify its January announcement that it would examine whether the AfD had breached constitutional safeguards against extremism.

“Legally speaking this is a total victory for the AfD,” the party co-leader Alexander Gauland told reporters.

The court said the BfV’s announcement was disproportionate and breached constitutional rules protecting political parties.

“The description as a ‘case to investigate’ gives a negative public impression,” the court’s ruling read, adding that an evaluation of AfD policies and views was not relevant.

A spokeswoman for the BfV said it was considering whether to appeal the court’s decision.

Germany’s constitution contains strict protections against extremism but also sets out democratic safeguards for political parties.

Gauland said the court ruling was a signal for other parties to rethink their attitude toward the AfD. “I advise our political competitors - meaning the other parties in parliament - to stop exploiting the BfV,” Gauland said. “Putting pressure on public servants leads to bad decisions.”

The BfV’s credibility was tarnished last year by accusations that its then-director, Hans-Georg Maassen, harbored far-right sympathies.

Maassen was replaced by Haldenwang in September after a public backlash against comments in which he questioned the authenticity of video footage showing radicals hounding migrants in the eastern city of Chemnitz.

AfD co-chief Alice Weidel said the court’s decision was proof Haldenwang lacked the “neutrality” needed to head the agency in charge of protecting the constitution, and called for his dismissal.

The AfD entered parliament for the first time in 2017 by scooping up voters angry with Chancellor Angela Merkel’s 2015 decision to welcome almost one million mainly Muslim asylum seekers.

Polls indicate the AfD is running almost neck-and-neck with Merkel’s Christian Democrats in the eastern states of Saxony and Thuringia, which vote on Sept. 1 and Oct. 27 respectively. It is forecast to come third in the eastern state of Brandenburg.