The decision by Judge Michal Jakubowski is the latest development surrounding contentious, confusing preparations for an Independence Day march on Sunday in the Polish capital to honor the country's 100 years of independence.
For the past decade, far-right nationalists have been organizing marches on the Nov. 11 Independence Day in Warsaw, and this year fears of open demonstrations of extremism and possible clashes with counter-protesters threatened to overshadow all other events on the nation's centenary calendar.
Last year marchers carried xenophobic banners proclaiming the desire for a "White Europe" that drew international criticism, especially coming only a few months after a violent rally of white nationalists in Charlottesville, Virginia.
Polish government officials had tried for months to persuade the nationalists to make the Warsaw march this year an inclusive affair involving state officials without any provocative banners but the two sides were unable to agree.
On Wednesday, Warsaw's city mayor stepped in and banned the march, citing security reasons. The president and prime minister then quickly announced that an inclusive state march would take place instead Sunday along the same route, led by President Andrzej Duda and including the prime minister, other top leaders and World War II veterans.
After the court ruling, it wasn't immediately clear if both marches will go ahead separately, or as one.
The uncertainties about security had been heightened by a mass walk-out by police officers in recent days over pay, prompting the government to ask the Defense Ministry to help with security on Sunday. But late Thursday a police union announced it was ending the protest after agreeing upon a deal with the Interior Ministry.
The Warsaw court ruling follows a similar ruling in Wroclaw on a city ban on a nationalist march there for Sunday.
City authorities still have the right to appeal the rulings.
Warsaw city spokesman Bartosz Milczarczyk said "we respect the court's verdict." He said town hall officials were studying it before deciding whether to appeal.
Earlier in the day, before the ruling, Prime Minister Mateusz Morawiecki said authorities would do everything in their power to crack down on any expressions of extremism at the march.
"We want the march to be peaceful and not provoke tensions," Morawiecki told reporters.
His comments come amid other signs that Poland's conservative ruling Law and Justice party is now seeking to take a firmer stance against ultra-nationalists after a period in which they seemed to be trying to appease them.
Extremists from Hungary and elsewhere have in past years joined Poland's Nov. 11 march, which is meant to mark Poland's regaining of its independence at the end of World War I.
Saying he expected up to 200,000 participants Sunday at the inclusive Warsaw march, Morawiecki acknowledged it could be hard to control them all, but said "we will try to eliminate all banners which are extremist."
He also said there will be no tolerance for foreign neo-fascists or other agitators.
Many other World War I centennial events are expected across the country on Sunday, with the most emotional expected to be the public singing of the national hymn at noon in hundreds of places.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.