WASHINGTON — President Obama, in a striking legal and political shift, has determined that the Defense of Marriage Act — the 1996 law that bars federal recognition of same-sex marriages — is unconstitutional, and has directed the Justice Department to stop defending the law in court, the administration said Wednesday.

Attorney General Eric H. Holder Jr. announced the decision in a letter to members of Congress. In it, he said the administration was taking the extraordinary step of refusing to defend the law, despite having done so during Mr. Obama’s first two years in the White House.

“The president and I have concluded that classifications based on sexual orientation” should be subjected to a strict legal test intended to block unfair discrimination, Mr. Holder wrote. As a result, he said, a crucial provision of the Defense of Marriage Act “is unconstitutional.”

Conservatives denounced the shift, gay rights advocates hailed it as a watershed, and legal scholars said it could have far-reaching implications beyond the marriage law. For Mr. Obama, who opposes same-sex marriage but has said repeatedly that his views are “evolving,” there are political implications as well. Coming on the heels of his push for Congress to repeal the “don’t ask, don’t tell” law barring the military from allowing gay people to serve openly, the administration’s move seems likely to intensify the long-running cultural clash over same-sex marriage as the 2012 political campaign is heating up.