Story highlights An appeals court says the Northern California school's decision kept students safe

Live Oak High School's principal told students to take off American flag T-shirts

The students later filed a civil rights suit against the school and administrators

The incident unfolded on Cinco de Mayo in 2010

A California school that stopped students from wearing American flag T-shirts on Cinco de Mayo didn't violate their constitutional rights, an appeals court ruled Thursday.

The school's approach, according to the appeals court, kept students safe in a climate of racial tension.

"The controversy and tension remained," a panel of judges from the 9th Circuit Court of Appeals said in their opinion , "but the school's actions presciently avoided an altercation."

School officials were worried about violence and disruption of school activities "and their response was tailored to the circumstance," the opinion said.

The case dates back to May 5, 2010, when the principal of Live Oak High School in Morgan Hill, California, asked a group of students wearing American flag T-shirts to turn their shirts inside out or take them off.

The students at the Northern California school refused, according to the appeals court's summary of the case, and later brought a civil rights suit against the school and two administrators, arguing that their rights to freedom of expression, equal protection and due process had been violated.

Judges said the civil rights case forced them to weigh the difficult question of what takes precedence: students' free speech rights or school safety concerns?

According to court documents, the incident occurred amid "ongoing racial tension and gang violence within the school, and after a near-violent altercation had erupted during the prior Cinco de Mayo over the display of an American flag."

The previous year, court documents said, a group of students carrying a Mexican flag had clashed with students who hung an American flag from a tree and chanted "USA" on Cinco de Mayo, a holiday marking a famous Mexican military battle that is often celebrated in the United States.

In 2010, the appeals court said, "threats issued in the aftermath of the incident were so real that the parents of the students involved in the suit kept them home from school two days later."

CNN first learned of the court's ruling on Twitter.