Harvard can continue to use race as a factor in its admissions process, a federal judge ruled Tuesday.

An anti-affirmative-action group, Students for Fair Admissions, had sued the Ivy League university in 2014, arguing that the school was admitting members of under-represented ethnic groups at the expense of more qualified Asian-Americans.

But while Judge Allison Burroughs admitted the institution’s admissions process is “not perfect,’’ she said it still “passes constitutional muster.”

“Ensuring diversity at Harvard relies, in part, on race-conscious admissions,” Burroughs contended in her written ruling.

She said one of the benefits of such policies is that more diversity on campus provides students with “the opportunity to know and understand one another beyond race.”

“Race-conscious admissions programs that survive strict scrutiny will have an important place in society and help ensure that colleges and universities can offer a diverse atmosphere that fosters learning, improves scholarship and encourages mutual respect and understanding,” the judge predicted.

The plaintiff immediately vowed to appeal the decision.

Experts say the battle could go all the way to the US Supreme Court.