PHOENIX — A U.S. judge has permanently blocked an ethnic studies ban in Arizona public schools that dismantled a popular Mexican-American studies program, dealing a final blow to a law that he found to be racially motivated.

Following a seven-year court battle, U.S. District Judge A. Wallace Tashima issued a final judgment Wednesday that prohibits Arizona education officials from enforcing the 2010 law, which stirred up more allegations of racial discrimination by a state that passed a landmark crackdown on immigration the same year.

Tashima had previously ruled that racism and political gain were behind the ban's creation, findings that he reiterated in this week's decision.

Because the law "was enacted and enforced, not for a legitimate educational purpose, but for an invidious discriminatory racial purpose, and a politically partisan purpose ... (the law) cannot be enforced," he wrote.

Attorneys for the state have denied that racial discrimination played a part in the law. The Arizona Attorney General's Office, which defended education officials in the case, said it may appeal the ruling.

"We will consult with the superintendent and see how she would like to proceed," spokesman Ryan Anderson said. "Additionally, we have an obligation to evaluate the likelihood of success on appeal for the individual findings."

Arizona Superintendent of Public Instruction Diane Douglas and the state Board of Education did not immediately reply to messages seeking comment Thursday.

The law banned courses appearing to promote resentment toward a race or class of people or advocate ethnic solidarity instead of treating people as individuals.

Lawmakers passed it after Tucson Unified School District began offering classes in 1998 focused on Mexican-American history, literature and art.

Steven Reiss, an attorney for Tucson students who sued over the law, was pleased by the ruling.

"That should make it clear to everyone in the state: This law is not only invalid and cannot be enforced, it makes it clear that the Tucson Unified School District is absolutely free to readopt the Mexican-American studies program," Reiss said.

The Tucson district ceased the classes in 2012 to avoid the threat of losing 10 percent of their state funding as a penalty. District officials did not immediately respond to messages seeking comment Thursday.

Democratic Rep. Sally Ann Gonzales of Tucson praised the ruling.

"Attacking the Mexican-American studies program sends the wrong message to Arizona's students and denies the state's rich and diverse history," Gonzales said in a statement. "It is important for Arizona to teach the history of minority communities of the past and present day."

During a July trial over the lawsuit, Tom Horne, a former state attorney general and state superintendent, defended the law he drafted. He testified that he was troubled by what he described as radical instructors teaching students to be disruptive but insisted he targeted all ethnic studies programs equally.

Education officials can move to dissolve the injunction once it expires in seven years, the judge said.

FOLLOW NBC LATINO ON FACEBOOK, TWITTER AND INSTAGRAM.