The Supreme Court on Monday struck down several key parts of Arizona’s tough law on illegal immigrants, but it left standing a controversial provision requiring police to check the immigration status of people they detain and suspect to be in the country illegally.

The 5 to 3 decision upholding the “show me your papers” provision came with a warning that the courts would be watching its implementation. Arizona Gov. Jan Brewer (R) declared victory and said police could enforce the law without resorting to profiling based on ethnicity.

But the ruling, which re­inforced the federal government’s primacy in immigration policy, also vindicated the Obama administration’s decision to challenge the Arizona law almost from the moment it was passed.

The justices will rule Thursday on the constitutionality of President Obama’s most important priority before the court: the health-care law, his signature domestic achievement. It will be the final day of a term that has been dominated by questions about the power of the federal government.

The immigration decision comes as the issue has taken a central spot in the nation’s political conversation and domestic agenda, even as the numbers of illegal immigrants coming to this country have fallen. It is likely to be just one in a series of court decisions about the role states may play in combating illegal immigration; five states have adopted laws similar to Arizona’s, and others are waiting in the wings.

Obama recently ignited new controversy by announcing that many immigrants under age 30 who were brought to this country illegally by their parents would not be deported. In an unusual moment Monday, a dissenting Justice Antonin Scalia mentioned Obama’s policy as he spoke from the bench to criticize the majority’s decision.

In oral arguments on the Arizona law, the justices had seemed skeptical of the administration’s vision of the subordinate role states must play in immigration matters.

But Justice Anthony M. Kennedy spelled out states’ limited role, even as he acknowledged criticism that the failure of Congress and the executive branch to form a comprehensive immigration strategy has led to severe hardships.

“Arizona may have under­standable frustrations with the problems caused by illegal immigration while that process continues,” he wrote, “but the state may not pursue policies that undermine federal law.”

The court threw out three such provisions in the Arizona law. It said the state cannot make it a misdemeanor for immigrants to not carry registration documents; criminalize the act of an illegal immigrant seeking employment; or authorize state officers to arrest someone on the belief that the person has committed an offense that makes him deportable.

Kennedy wrote for Chief Justice John G. Roberts Jr. and Justices Ruth Bader Ginsburg, Stephen G. Breyer and Sonia Sotomayor. Justice Elena Kagan recused herself from the case, presumably because she had worked on it while serving as Obama’s solicitor general.

Scalia and Justices Clarence Thomas and Samuel A. Alito Jr. wrote dissents from the decision. In reading his dissent, Scalia made clear the extent of his disagreement.

“Arizona has moved to protect its sovereignty — not in contradiction of federal law, but in complete compliance with it,” he wrote. “If securing its territory in this fashion is not within the power of Arizona, we should cease referring to it as a sovereign state.”

Scalia took aim at Obama’s new policy on deportation in the statement he read from the bench, as well as in his dissent, although the issue was not before the court.

“The husbanding of scarce enforcement resources can hardly be the justification for this, since those resources will be eaten up by the considerable administrative cost of conducting the nonenforcement program, which will require as many as 1.4 million background checks and biennial rulings on requests for dispensation,” Scalia said.

He went on: “But to say, as the court does, that Arizona contradicts federal law by enforcing applications of federal immigration law that the president declines to enforce boggles the mind.”

Brewer, in a statement, accentuated the positive in the ruling about her state’s statute. “After more than two years of legal challenges, the heart of S.B. 1070 can now be implemented in accordance with the U.S. Constitution,” she said.

She said the law will not result in profiling. “Law enforcement will be held accountable should this statute be misused in a fashion that violates an individual’s civil rights,” she said.

The justices made clear at oral arguments that they were not considering charges that the provision allowing police to check immigration status would lead to profiling. Kennedy explained in his decision that because the administration had challenged the law before its implementation, it would be improper to block it now.

But he seemed to say that courts would be watching. “This opinion does not foreclose other preemption and constitutional challenges to the law as interpreted and applied after it goes into effect,” he wrote.

The Obama administration has taken a tough stance against the Arizona law and against similar laws in most other states that have implemented them. Its lawyers went to court early to block S.B. 1070 and won at both the district court level and the U.S. Court of Appeals for the 9th Circuit.

In a statement Monday, Obama said that he was “pleased that the Supreme Court has struck down key provisions of Arizona’s immigration law.” He added that the decision makes clear “that Congress must act on comprehensive immigration reform,” since a “patchwork of state laws is not a solution to our broken immigration system.” At the same time, he said, he remains “concerned about the practical impact” of the part of the law that was allowed to stand.

“No American should ever live under a cloud of suspicion just because of what they look like,” Obama said. “Going forward, we must ensure that Arizona law enforcement officials do not enforce this law in a manner that undermines the civil rights of Americans, as the Court’s decision recognizes.”

Republican presidential candidate Mitt Romney issued a statement that did not comment on the specifics of the ruling but instead said that it “underscores the need for a President who will lead on this critical issue and work in a bipartisan fashion to pursue a national immigration strategy.”

Obama “has failed to provide any leadership on immigration,” the former Massachusetts governor said.

Romney did not speak to reporters accompanying him on a campaign trip to Arizona, and aides refused to say whether he agrees with the Supreme Court’s ruling or whether he supports Arizona’s immigration policy.

“The governor supports the states’ rights to craft immigration laws when the federal government has failed to do so,” spokesman Rick Gorka said. “That’s all we’re going to say on this issue.”

The case is Arizona v. United States.

Staff writers N.C. Aizenman and William Branigin in Washington and Philip Rucker in Scottsdale, Ariz., contributed to this report.