The 10-page ruling issued late Monday by Jefferson County Circuit Judge Michael Graffeo said a 2017 state law barring the removal or alteration of historical monuments wrongly violated the free speech rights of local communities.
The law can't be enforced, Graffeo ruled, but the state attorney general's office said it would appeal.
The state sued the city of Birmingham after officials tried to remove a 52-foot-tall (16-meter)-tall obelisk that was erected to honor Confederate veterans in a downtown park in 1905. Rather than toppling the stone marker, the city built a 12-foot (3.6-meter)-tall wooden box around it.
Birmingham's population of 210,000 is more than 70 percent black, and the judge said it was indisputable that most citizens are "repulsed" by the memorial. He rejected the state's claims that lawmakers had the power to protect historical monuments statewide.
Birmingham Mayor Randall Woodfin told The Associated Press he was happy with the ruling.
"We were not even a city during the Civil War," he said.
But Woodfin, citing the state's plan to appeal, said the monument can't be taken down immediately.
"We'll weigh our options," he said.
The law includes a $25,000 penalty for removing or altering a historical monument, but the judge said the penalty was unconstitutional. The city hasn't had to pay while the lawsuit worked its way through court.
The ruling came hours after the inauguration of Republican Gov. Kay Ivey, who signed the law and opened her campaign last year with a commercial that prominently showed Confederate monuments.
"We can't change or erase our history, but here in Alabama we know something that Washington doesn't. To get where we are going means understanding where we have been," Ivey said in the ad.
Supporters of the law contend it protects not just Confederate memorials but historical markers of any kind, but rebel memorials have been an issue nationwide since a white supremacist gunman killed nine worshippers in a black church in Charleston, South Carolina, in 2015.
State Sen. Gerald Allen, the Tuscaloosa Republican who sponsored the legislation, said in a statement that the law was meant to "thoughtfully preserve the entire story of Alabama's history for future generations."
"The attorney general's office is confident that the Memorial Preservation Act is constitutional, and I look forward to the attorney general's appeal of Judge Graffeo's ruling," Allen said.