While the conservative-dominated high court ruling released Monday found much of the Arizona law unconstitutional, it did rule that one part would stand - the portion requiring police to check the status of someone they suspect is not in the United States legally. Even there, though, the justices said the provision could be subject to additional legal challenges.
Obama issued a statement declaring he was "pleased" with the ruling, but cautioned that the enforcement provision left standing was wrong.
"No American should ever live under a cloud of suspicion just because of what they look like," Obama said in a statement. "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."
Romney did not immediately comment on the court decision Monday, but he said, "I believe that each state has the duty - and the right - to secure our borders and preserve the rule of law, particularly when the federal government has failed to meet its responsibilities."
Arizona's long southern boundary borders Mexico.
The Arizona decision landed in the middle of a presidential campaign in which Obama has been heavily courting Latino voters and Romney has been struggling to win Latino support. During a drawn-out primary campaign, Romney and the other Republican candidates mostly embraced a hard line to avoid accusations that they support any kind of "amnesty" for illegal immigrants living in the U.S.
Romney has lately taken a softer tone on immigration as a result of Obama's having issued an executive ruling that ends deportation of young people brought illegally into the country as children.
The Obama administration had assailed the Arizona law as an unconstitutional intrusion into an area under Washington's control, and the court struck down provisions that would have made state crimes out of federal immigration violations.
But several lawmakers and civil rights groups said the part of the law left in place by the high court was an invitation to racial profiling.
The court announced that Thursday would be the last day of rulings this term, which means the decision on President Barack Obama's landmark health care overhaul probably will come that day.
The Arizona decision upholds the "show me your papers" provision for the moment. But it takes the teeth out of it by prohibiting police officers from arresting people on minor immigration charges.
In Monday's decision, the court was unanimous on allowing the immigration status check to go forward. The justices were divided on striking down the other portions.
Justice Anthony Kennedy said the law could - and suggested it should - be read to avoid concerns that status checks could lead to prolonged detention.
The court struck down these three major provisions: requiring all immigrants to obtain or carry immigration registration papers, making it a state criminal offense for an illegal immigrant to seek work or hold a job and allowing police to arrest suspected illegal immigrants without warrants.
Arizona Gov. Jan Brewer, a Republican, said the ruling marked a victory for people who believe in the responsibility of states to defend their residents. The case, she said, "has always been about our support for the rule of law. That means every law, including those against both illegal immigration and racial profiling. Law enforcement will be held accountable should this statute be misused in a fashion that violates an individual's civil rights."
Civil rights groups that separately challenged the law over concerns that it would lead to rights abuses said their lawsuit would go on.
Even with the limitations the high court put on Arizona, the immigration status check still is "an invitation to racial profiling," said American Civil Liberties Union lawyer Omar Jadwat.
The Obama administration sued to block the Arizona law soon after its enactment two years ago. Federal courts had refused to let the four key provisions take effect.
Five states - Alabama, Georgia, Indiana, South Carolina and Utah - have adopted variations on Arizona's law. Parts of those laws also are on hold pending the outcome of the Supreme Court case.
The Arizona case focused on whether states can adopt their own measures to deal with an estimated 11 million illegal immigrants in the face of federal inaction on comprehensive reform, or whether the federal government has almost exclusive authority in that area.
Kennedy wrote obliquely about the impasse at the national level.
"Arizona may have understandable frustrations with the problems caused by illegal immigration while that process continues, but the state may not pursue policies that undermine federal law," Kennedy said.
GET THE LATEST NATIONAL AND INTERNATIONAL NEWS FROM ABCNEWS.COM ---
Get Eyewitness News Delivered