WASHINGTON — A deeply divided Supreme Court upheld the use of racial preferences in admissions at the University of Texas Thursday, giving an unexpected reprieve to the type of affirmative action policies it has condoned for nearly four decades.

The 4-3 ruling did not address all programs designed to attract a diverse student body at colleges and universities, which the court endorsed twice in 1978 and 2003. But Justice Anthony Kennedy and the court’s more liberal justices said Texas’ unique method of singling out some minority students for admission to its flagship campus in Austin was constitutional.

The dramatic decision was made without Justice Antonin Scalia, who died Feb. 13, and Justice Elena Kagan, who recused herself because she worked on the case as U.S. solicitor general before joining the court. It was the second time the high court had considered it; in 2013, the justices sent the case back to a federal appeals court with instructions to more closely scrutinize the university’s program, but that court again sided with the school.

This time, it appeared during oral argument that a majority of justices were prepared to rule that the school’s use of race violated the Constitution’s equal protection clause by giving minority students a leg up. The university already admits minority students by accepting a set percentage of top-ranked students from all high schools that use such rankings, including those in heavily minority neighborhoods.

The case had threatened the use of racial preferences not only at the University of Texas-Austin but across the nation, since the court’s ruling could have cast doubt on most affirmative action policies. In that sense, the narrow decision targeting only the Texas policy amounted to a partial victory for proponents of affirmative action.

The court’s conservative justices made clear, however, that they were impatient with the continued use of affirmative action, more than a decade after a ruling by Justice Sandra Day O’Connor upheld racial preferences in college admissions but said they should be unnecessary in 25 years. Justice Samuel Alito announced his dissent from the bench, with Chief Justice John Roberts and Justice Clarence Thomas agreeing.

Scalia, whose sudden death and Senate Republicans’ refusal to consider a successor until next year, has left the court in limbo. During oral argument in December, Scalia expressed the most controversial opinions. Citing briefs that suggest African Americans may fare better at “less advanced” or “slower-track” schools, he said, “­I don’t think it stands to reason that it’s a good thing for the University of Texas to admit as many blacks as possible.”

The court’s liberal justices stood firmly behind the continued use of racial preferences, something the high court upheld in California in 1978 and then in Michigan a quarter century later. They argued that the university at least should be able to prove its case at a fact-finding hearing in Texas before the court considers striking down its program.

That left Kennedy, as usual, as the swing vote. He complained that, more than two years after his 7-1 opinion sent the case back to a federal appeals court for closer scrutiny, little had changed.

“We’re just arguing the same case,” Kennedy groused. “It’s as if nothing had happened.”

The case was brought by Abigail Fisher, a white woman denied entry to her state’s flagship university. She ultimately graduated from Louisiana State University but had continued to press her case with the aid of the Project on Fair Representation, a conservative legal group.

The school’s first method of integration — accepting the top students from every high school that uses class rankings — wasn’t challenged, even though it “trades on the de facto segregation that still exists in Texas” to pull in minorities, the school’s Supreme Court brief noted.

What was contested is the second method — a topping-off of each freshman class by focusing on a variety of factors, from special talents and extracurricular activities to socioeconomics, race and ethnicity. Those last factors are used to produce what the school calls “diversity within diversity” — a representative mix of minority students, rather than just those from segregated communities with similar backgrounds and experiences.