Saying they came to power through “unlawful elections,” a judge ordered the entire Palmdale City Council removed from office by July and called a special election to give minorities a fair chance to seat their choice of candidates.

Palmdale plans to appeal.

In what could be a precedent-setting decision, Los Angeles County Superior Court Judge Mark Mooney scrapped Palmdale’s at-large elections — in which all voters choose from the same a common pool of candidates — in favor of dividing the city into four districts that would each choose a council member.

Two of the new districts would have a majority Latino population.

In his tentative ruling, dated Nov. 27, Mooney wrote Palmdale has an “established history of racially polarized voting” and ordered it to hold a special election coinciding with statewide primaries June 3.

“The Latino and African American citizens of Palmdale deserve to have their voices heard in the operation of their city,” Mooney wrote.

Though the Census shows Palmdale is almost 60 percent Hispanic, and 15 percent African-American, only one Hispanic and one African-American have been elected to its council since the 1970s.

R. Rex Parris, the lawyer for the plaintiffs and mayor of neighboring Lancaster, said the ruling should “break the stranglehold” of the political “machine” that “controls” Palmdale.

“Palmdale has very clear areas where Hispanics and African-Americans represent the majority but they’ve never been able to get anyone elected to the council because their city has been run by a group of very few people for the last 25 years who control all the campaign funding,” Parris said.

He said the ruling could set a precedent for Anaheim and Whittier, as well as school districts in Santa Clarita and Lancaster, which have also been sued for holding at-large elections.

Neighborhood Legal Services Executive Director Neal Dudovitz, who was not involved in this case but represented minorities who accused both Palmdale and Lancaster of harassing them over federal housing assistance vouchers, hailed the ruling.

“Given the very recent history of discrimination in Palmdale, we are encouraged that the court is enforcing those laws that protect minorities and ensure a more fair representation that is reflective of the diversity of the Antelope Valley,” Dudovitz said.

But Palmdale deputy city attorney Noel Doran denied minorities in Palmdale have been disenfranchised.

“The city believes it’s in the best interest of our citizens to elect their council members at large, as opposed to being able to select only one council member (their district representative),” he said.

Palmdale held elections only last month, putting Frederick Thompson and Tom Lackey on the council through 2017.

Steven Hofbauer and Mike Dispenza were supposed to remain in office through 2015.

Under Mooney’s ruling, however, all would have to be removed by July 9. If they want to stay, they would have to run for re-election.

Doran found it ironic that Parris is suing Palmdale when Lancaster also has at-large elections, and that the ruling would prevent Thompson — an African-American — from keeping his seat on the council.

“This isn’t about black or brown, but about green,” Doran said. “The whole motive behind the lawsuit is money (for the attorneys).”

Doran said the city plans to file an appeal as soon as the ruling is finalized.