The U.S. Supreme Court ruling giving gay people the right to marry in all 50 states is vindication of the belief that "ordinary people can do extraordinary things" and has "made our union a little more perfect," President Barack Obama said Friday.

The court ruled that allowing states to deny gay people the right to marry is a violation of the 14th Amendment.

In a 5-4 decision released Friday, the court ruled that the amendment obliges states to license marriages between people of the same sex and to recognize marriages lawfully performed outside of state. Thirty-seven of the 50 states and the District of Columbia already allow gay marriage, and Friday's ruling means the others will have to follow suit.

The ruling only affects state laws. Religious institutions can still choose whether or not to marry same-sex couples.

'[The decision] affirms what millions of Americans already believe in their hearts.'- U.S. President Barack Obama

Obama called the decision "a victory for America" and said it "affirms what millions of Americans already believe in their hearts."

"When all Americans are treated equal, we are all more free," he said from the White House Rose Garden.

He praised the perseverance of those who have fought for gay rights and marriage equality for decades "and slowly made an entire country realize that love is love."

US Supreme Court Gay Marriage Texas

Aixa Adame, left, and Lacey Darcy exchange vows in front of Judge Laura Strathmann in the 388th District Courtroom in El Paso, Texas. They were the first female couple to be married in El Paso. (Victor Calzada/The El Paso Times/Associated Press)

"Change must have seemed so slow for so long," Obama said. "But compared to so many other issues, America's shift has been so quick."

Outside of the court in Washington, D.C., gay couples and gay rights supporters erupted in cheers, whoops and cries of U-S-A!" and "Love is love" when the ruling came down.

"I'm simply elated," said Kenneth Barnes, waving a rainbow flag he's had for more than 20 years. "I never thought I'd see this in my lifetime," 

Barnes and his partner married in California in 2008. "Now, everyone can do this," he said.

Many same-sex couples living in states where gay marriage had been banned headed immediately to county clerks' offices to get marriage licences as state officials issued statements saying they would respect the ruling. Technically, the losing side has three weeks to ask for reconsideration of the ruling, but many state officials and county clerks started issuing marriage licences right away.

Some waived the usual waiting period between getting a licence and the marriage ceremony.

Equal protection for all

The 14th Amendment affords equal protection under the law to all citizens and was key in other landmark decisions on such divisive issues as reproductive rights and racial and gender discrimination (for example, in Brown v. Board of Education, and Roe v. Wade).

The top court ruled it would be a violation of the amendment to grant marriage rights only to heterosexual couples.

"No union is more profound than marriage, for it embodies the highest ideals of love, fidelity, devotion, sacrifice and family. ... [The challengers] ask for equal dignity in the eyes of the law. The constitution grants them that right," Justice Anthony Kennedy wrote in the majority opinion.

Obama welcomed the decision with a tweet and a phone call to the lead plaintiff in the case, James Obergefell.

"I'm really proud of you and just know that not only did you set a great example for people, but you're also going to bring about lasting change in this country," he told him in the call, which Obergefell took as he was celebrating in front of the Supreme Court and put on speaker so the crowd could lsiten in. 

Supreme Court Gay Marriage The Plaintiffs

'From this day forward, it will simply be "marriage,"' James Obergefell, the lead plaintiff in the case, said after the landmark ruling. (Andrew Harnik/Associated Press)

Obergefell was in court when Kennedy read the decision and afterward held up a photo of his late spouse, John, outside the court building, saying the ruling establishes that "our love is equal." 

"This is for you, John." he said. 

"From this day forward, it will simply be 'marriage.'"

The White House donned rainbow colours, a symbol of the gay rights movement, on its Twitter and home page in celebration of the ruling.

In its ruling, the Supreme Court said the "long history of disapproval of their relationships" and the denial of the right to marry has done a "grave and continuing harm" to same-sex couples.

US-Supreme Court-Gay Marriage Mississippi

Laurin Locke, 24, left, and her partner, Tiffany Brosh, 26, of Pearl, Miss., applied for a marriage licence at the Hinds County Circuit Clerk's office in Jackson, Miss., moments after the U.S. Supreme Court ruling came down. (Rogelio V. Solis/Associated Press)

"The imposition of this disability on gays and lesbians serves to disrespect and subordinate them," Kennedy wrote. "And the equal protection clause, like the due process clause, prohibits this unjustified infringement of the fundamental right to marry."

Kennedy, a conservative appointed by Republican President Ronald Reagan in 1988 who often casts the deciding vote in close cases, has authored all four of the court's major gay rights rulings, with the first coming in 1996.

Justice Antonin Scalia wrote the most scathing of the four dissenting opinions, calling the decision a" threat to American democracy" and ridiculing the flowery language of the majority opinion.

Supreme Court Gay Marriage Michigan

Eric Braman, right, is hugged by his best man after registering for a marriage licence with his partner Kris Katkus, in Kalamazoo, Mich. (Mark Bugnaski/Kalamazoo Gazette-MLive Media Group/Associated Press)

"If, even as the price to be paid for a fifth vote, I ever joined an opinion for the court that began: 'The Constitution promises liberty to all within its reach, a liberty that includes certain specific rights that allow persons, within a lawful realm, to define and express their identity,' I would hide my head in a bag," Scalia wrote.

"The Supreme Court of the United States has descended from the disciplined legal reasoning of John Marshall and Joseph Story to the mystical aphorisms of the fortune cookie." 

Scalia took strong issue with the majority interpretation of the 14th Amendment.

"The five Justices who compose today's majority are entirely comfortable concluding that every state violated the Constitution for all of the 135 years between the 14th Amendment's ratification and Massachusetts's permitting of same-sex marriages in 2003," he wrote. "They have discovered in the 14th Amendment a 'fundamental right' overlooked by every person alive at the time of ratification, and almost everyone else in the time since."

The other dissenters were justices Samuel Alito, Clarence Thomas and John Roberts.

Roberts said there are compelling policy arguments for extending marriage to same-sex couples but no legal argument to justify forcing states to change their marriage laws.

"The fundamental right to marry does not include a right to make a state change its definition of marriage," he wrote. "Our constitution does not enact any one theory of marriage. The people of a state are free to expand marriage to include same-sex couples, or to retain the historic definition."

He said that while he doesn't begrudge supporters of gay marriage their celebrations, the court overstepped in handing down a ruling that "orders the transformation of a social institution that has formed the basis of human society for millennia, for the Kalahari bushmen and the Han Chinese, the Carthaginians and the Aztecs."

"Just who do we think we are?" he wrote.

Roberts and other dissenters predicted further legal wrangles from those opposed to same-sex marriage on religious grounds.

Political Conservatives also denounced the ruling. Republican presidential candidate Mike Huckabee called it "an out-of-control act of unconstitutional judicial tyranny."

Wisconsin Republican Governor Scott Walker, also running for president, called for amending the U.S. Constitution to allow states to again ban same-sex marriage. Texas Republican Governor Greg Abbott said, "Marriage was defined by God. No man can redefine it."

Plaintiffs' arguments

The court was examining two key questions:

  • Whether states can ban same-sex marriage.
  • Whether states with gay marriage bans can refuse to recognize marriages performed in other jurisdictions where same-sex marriage is legal.

The plaintiffs had argued that the court had already acknowledged marriage is a fundamental right in previous decisions and that they were merely seeking equal access to this right.

US Supreme Court same sex decision June 26 85965417 April DeBoer Jayne Rowse

Jayne Rowse, left, and partner April DeBoer were among the five plaintiffs whose cases made up the challenge of gay marriage bans before the Supreme Court. (Bill Pugliano/Getty)

The challenge of state bans on gay marriage joined together the cases of Obergefell, April DeBoer, Jayne Rowse, Ijpe DeKoe and Thomas Kostura.

DeKoe and Kostura legally married in New York but then moved to Tennessee, where their marriage wasn't recognized.

Obergefell legally married his partner of 20 years, John Arthur, in Maryland, but was not recognized as his legal spouse when Arthur died a few months later in Ohio.

DeBoer and Rowse have three children together but were prevented from jointly adopting them or having them covered under each other's health insurance because they were not legally married, and couldn't get married because their home state of Michigan doesn't recognize same-sex marriage.

Ruling follows other key victories in gay rights movement

The court's latest decision is the most important expansion of marriage rights in the United States since its landmark 1967 ruling in the case Loving v. Virginia that struck down state laws barring interracial marriages.

The ruling is the latest milestone in the gay rights movement in recent years. In 2010, Obama signed a law allowing gays to serve openly in the U.S. military. In 2013, the Supreme Court  struck down a provision of the federal Defence of Marriage Act that defined marriage as a union between a woman and man and prevented same-sex couples married in states where such unions are legal from accessing certain federal programs and filing tax returns as a married couple, for example.

The U.S. is the latest of many Western countries to recognize same-sex marriage. Last month, voters in Ireland backed same-sex marriage by a landslide in a referendum that marked a dramatic social shift in the traditionally Roman Catholic country.

Gay marriage is also legal in Canada, South Africa, Brazil, Britain, France and Spain, but many parts of Africa and Asia consider it — and homosexuality in general — taboo and often illegal.

With files from Reuters and The Associated Press