Washington (CNN) In a landmark opinion, a divided Supreme Court on Friday ruled that same-sex couples can marry nationwide, establishing a new civil right and handing gay rights advocates a historic victory.

In the 5-4 ruling, Justice Anthony Kennedy wrote for the majority with the four liberal justices. Each of the four conservative justices wrote their own dissent.

Nearly 46 years to the day after a riot at New York's Stonewall Inn ushered in the modern gay rights movement, the decision could settle one of the major civil rights fights of this era. The language of Kennedy's opinion spoke eloquently of the most fundamental values of family, love and liberty.

Celebrations at the Supreme Court after marriage ruling

Celebrations at the Supreme Court after marriage ruling 01:32

Celebrations at the Supreme Court after marriage ruling

"No union is more profound than marriage, for it embodies the highest ideals of love, fidelity, devotion, sacrifice and family," Kennedy wrote. "In forming a marital union, two people become something greater than they once were."

'Equal dignity in the eyes of the law'

"Their hope," Kennedy wrote, "is not to be condemned to live in loneliness, excluded from one of civilization's oldest institutions. They ask for equal dignity in the eyes of the law. The Constitution grants them that right."

Photos: Same-sex marriage in the U.S. Photos: Same-sex marriage in the U.S. Carlos McKnight of Washington waves a flag in support of same-sex marriage outside the U.S. Supreme Court on June 26, 2015. The Supreme Court ruled 5-4 that states cannot ban same-sex marriage, handing gay rights advocates their biggest victory yet. See photos from states that approved same-sex marriage before the nationwide ruling: Hide Caption 1 of 33 Photos: Same-sex marriage in the U.S. Shante Wolfe, left, and Tori Sisson become the first same-sex couple to file their marriage license in Montgomery, Alabama, on February 9, 2015. However, seven months after the U.S. Supreme Court ruling legalizing such nuptials nationwide, Alabama Chief Justice Roy Moore directed probate judges in his state to enforce the ban on same-sex marriage. Gay rights organizations swiftly denounced Moore's January 6, 2016, order. Hide Caption 2 of 33 Photos: Same-sex marriage in the U.S. Newlyweds Jeff Delmay and Todd Delmay hug during a marriage ceremony in a Miami courtroom January 5, 2015. Florida began allowing same-sex marriages after a federal judge struck down the state's ban. Hide Caption 3 of 33 Photos: Same-sex marriage in the U.S. Chad Biggs, left, and Chris Creech say their wedding vows at the Wake County Courthouse in Raleigh, North Carolina, on October 10, 2014, after a federal judge ruled that same-sex marriage can begin in the state. Hide Caption 4 of 33 Photos: Same-sex marriage in the U.S. Joshua Gunter, right, and Bryan Shields attend a Las Vegas rally to celebrate an appeals court ruling that overturned Nevada's same-sex marriage ban on October 7, 2014. Hide Caption 5 of 33 Photos: Same-sex marriage in the U.S. From left, plaintiffs Moudi Sbeity; his partner, Derek Kitchen; Kody Partridge; and Partridge's wife, Laurie Wood, celebrate after a news conference in Salt Lake City on October 6, 2014. The U.S. Supreme Court cleared the way for same-sex marriage in Utah when it declined to hear the state's appeal of a lower court ruling. Hide Caption 6 of 33 Photos: Same-sex marriage in the U.S. Abbi Huber, left, and Talia Frolkis exit the City County Building in Madison, Wisconsin, after applying for a marriage license on October 6, 2014. Hide Caption 7 of 33 Photos: Same-sex marriage in the U.S. Rob MacPherson, right, and his husband, Steven Stolen, hug during a news conference at the American Civil Liberties Union in Indianapolis on October 6, 2014. Hide Caption 8 of 33 Photos: Same-sex marriage in the U.S. Mary Bishop, second from left, and Sharon Baldwin, right, celebrate with family and friends following their wedding ceremony on the courthouse steps in Tulsa, Oklahoma, on October 6, 2014. Hide Caption 9 of 33 Photos: Same-sex marriage in the U.S. Jennifer Melsop, left, and Erika Turner kiss after they were married in front of the Arlington County Courthouse in Arlington, Virginia, on October 6, 2014. Hide Caption 10 of 33 Photos: Same-sex marriage in the U.S. Pastor Carol Hill from Epworth United Methodist Church speaks during a marriage-equality ceremony at the Kathy Osterman Beach in Chicago on June 1, 2014. The date marked the first day that all of Illinois' 102 counties could begin issuing marriage licenses to same-sex couples. Hide Caption 11 of 33 Photos: Same-sex marriage in the U.S. William Roletter, left, and Paul Rowe get close after having their photo taken with their marriage certificate May 21, 2014, at Philadelphia City Hall. Hide Caption 12 of 33 Photos: Same-sex marriage in the U.S. Julie Engbloom, left, and Laurie Brown embrace after marrying in Portland, Oregon, on May 19, 2014. A federal judge struck down the state's voter-approved ban on same-sex marriage. Hide Caption 13 of 33 Photos: Same-sex marriage in the U.S. Jennifer Rambo, right, kisses her Kristin Seaton after their marriage ceremony in front of the Carroll County Courthouse in Eureka Springs, Arkansas, on May 10, 2014. Rambo and Seaton were the first same-sex couple to be granted a marriage license in Eureka Springs after a judge overturned Amendment 83, which banned same-sex marriage in Arkansas. Hide Caption 14 of 33 Photos: Same-sex marriage in the U.S. Same-sex couples get their marriage licenses at the Oakland County Courthouse in Pontiac, Michigan, on March 22, 2014, a day after a federal judge overturned Michigan's ban on same-sex marriage. Hide Caption 15 of 33 Photos: Same-sex marriage in the U.S. On November 13, 2013, Hawaii Gov. Neil Abercrombie, left, and former state Sen. Avery Chumbley celebrate with a copy of the Honolulu Star-Advertiser after Abercrombie signed a bill legalizing same-sex marriage in the state. Hide Caption 16 of 33 Photos: Same-sex marriage in the U.S. Utah state Sen. Jim Dabakis, left, and Stephen Justesen acknowledge the crowd after being married in Salt Lake City in December 20, 2013. Hide Caption 17 of 33 Photos: Same-sex marriage in the U.S. Plaintiffs Laurie Wood, left, and Kody Partridge, center, walk with attorney Peggy Tomsic on December 4, 2013, after a judge heard arguments challenging Utah's same-sex marriage ban. Hide Caption 18 of 33 Photos: Same-sex marriage in the U.S. On October 21, 2013, Cory Booker, right, officiates a wedding ceremony for Joseph Panessidi, center, and Orville Bell at the Newark, New Jersey, City Hall. The New Jersey Supreme Court denied the state's request to prevent same-sex marriages temporarily, clearing the way for same-sex couples to marry. Hide Caption 19 of 33 Photos: Same-sex marriage in the U.S. A couple celebrates at San Francisco City Hall upon hearing about the U.S. Supreme Court rulings on same-sex marriage on June 26, 2013. The high court cleared the way for same-sex couples in California to resume marrying after dismissing an appeal on Proposition 8 on jurisdictional grounds. The court also struck down a key part of the Defense of Marriage Act, a 1996 federal law defining marriage as between a man and a woman. Hide Caption 20 of 33 Photos: Same-sex marriage in the U.S. At the state Capitol in St. Paul, Minnesota, Gov. Mark Dayton signs a bill legalizing same-sex marriage on May 14, 2013. Hide Caption 21 of 33 Photos: Same-sex marriage in the U.S. Delaware Gov. Jack Markell holds up legislation on May 7, 2013, allowing same-sex couples to wed in the state. Hide Caption 22 of 33 Photos: Same-sex marriage in the U.S. Rhode Island state Sen. Donna Nesselbush, right, embraces a supporter after the Marriage Equality Act was signed into law at the statehouse in Providence on May 2, 2013. Hide Caption 23 of 33 Photos: Same-sex marriage in the U.S. Jamous Lizotte, right, and Steven Jones pose for photos while waiting for a marriage license in Portland, Maine, on December 29, 2012. Hide Caption 24 of 33 Photos: Same-sex marriage in the U.S. On March 1, 2012, Maryland Gov. Martin O'Malley, center, shakes hands with Senate President Thomas V. "Mike" Miller after signing a same-sex marriage bill. The law was challenged, but voters approved marriage equality in a November 2012 referendum. Hide Caption 25 of 33 Photos: Same-sex marriage in the U.S. On February 13, 2012, Washington Gov. Chris Gregoire celebrates after signing marriage-equality legislation into law. Voters there approved same-sex marriage in November 2012, defeating a challenge by opponents. Hide Caption 26 of 33 Photos: Same-sex marriage in the U.S. Phyllis Siegel, right, kisses her wife, Connie Kopelov, after exchanging vows at the Manhattan City Clerk's office on July 24, 2011, the first day New York's Marriage Equality Act went into effect. Hide Caption 27 of 33 Photos: Same-sex marriage in the U.S. On August 21, 2010, TV reporter Roby Chavez, right, shares a moment with gay rights activist Frank Kameny during Chavez and Chris Roe's wedding ceremony in the nation's capital. Same-sex marriage became legal in Washington in March 2010. Hide Caption 28 of 33 Photos: Same-sex marriage in the U.S. Olin Burkhart, left, and Carl Burkhart kiss on the steps of the New Hampshire Capitol on January 1, 2010, after the state's law allowing same-sex marriage went into effect. Hide Caption 29 of 33 Photos: Same-sex marriage in the U.S. In May 2009, Maine state Sen. Dennis Damon, left, hands Gov. John Baldacci the bill that the state Senate passed to affirm the right of same-sex couples to marry. Hide Caption 30 of 33 Photos: Same-sex marriage in the U.S. Amy Klein-Matheny, left, and her wife, Jennifer, exchange vows in Iowa after same-sex couples were allowed to marry there with an April 3, 2009, court ruling. Hide Caption 31 of 33 Photos: Same-sex marriage in the U.S. Michael Miller, left, and Ross Zachs marry on the West Hartford Town Hall steps after same-sex marriage became legal in Connecticut on November 12, 2008. Hide Caption 32 of 33 Photos: Same-sex marriage in the U.S. Lara Ramsey, left, and Jane Lohmann play with their 7-month-old son, Wyatt Ramsey-Lohmann. The two wed in 2004 after Massachusetts approved same-sex marriage. Massachusetts was the first state to do so. Hide Caption 33 of 33

Kennedy has written the opinion in significant gay rights cases and when he uttered the key sentence that same-sex couples should be able to exercise the right to marry in all states, people in the Court's public gallery broke into smiles and some wiped tears from their eyes.

In a dissent, Justice Antonin Scalia blasted the Court's "threat to American democracy."

"The substance of today's decree is not of immense personal importance to me," he wrote. "But what really astounds is the hubris reflected in today's judicial Putsch."

Chief Justice John Roberts wrote that the decision had "nothing to do with the Constitution."

"If you are among the many Americans—of whatever sexual orientation—who favor expanding same-sex marriage, by all means celebrate today's decision. Celebrate the achievement of a desired goal," he wrote. "Celebrate the opportunity for a new expression of commitment to a partner. Celebrate the availability of new benefits. But do not celebrate the Constitution. It had nothing to do with it."

The U.S. is now the 21st country to legalize same-sex marriage nationwide, including territories. Married same-sex couples will now enjoy the same legal rights and benefits as married heterosexual couples nationwide and will be recognized on official documents such as birth and death certificates.

Hundreds of same-sex marriage supporters flooded the plaza and sidewalk in front of the Court to celebrate the ruling, proudly waving rainbow flags and banners with the Human Rights Campaign's equal sign, which have come to represent the gay rights movement. In an emotional moment, the supporters sang the National Anthem, clapping wildly after singing that the U.S. is "the land of the free."

After the ruling, President Barack Obama called Jim Obergefell, the lead plaintiff in the case, while he and his supporters celebrated the ruling outside the court.

Obama: 'Congratulations'

"I just wanted to say congratulations," Obama said as CNN broadcast his warm words to Obergefell over speakerphone. He added: "Your leadership on this has changed the country."

JUST WATCHED Obama calls same-sex marriage plaintiff after victory Replay More Videos ... MUST WATCH Obama calls same-sex marriage plaintiff after victory 01:58

JUST WATCHED Celebration and pride on the steps of the Supreme Court Replay More Videos ... MUST WATCH

Speaking at the White House later in the morning, Obama said "Americans should be very proud," because small acts of courage "slowly made an entire country realize that love is love."

The decision affirmed growing public support in the U.S . for gay marriage, with about two-thirds of Americans now in favor. And it comes as gay rights groups have seen gay marriage bans fall rapidly in recent years, with the number of states allowing gay marriage swelling most recently to 37 -- that is, until this ruling.

There were two questions before the Court, the first asked whether states could ban same sex marriage, the second asked whether states had to recognize lawful marriages performed out of state.

The relevant cases were argued earlier this year. Attorney John Bursch, serving as Michigan's Special Assistant Attorney General, defended four states' bans on gay marriage before the Court, arguing that the case was not about how to define marriage, but rather about who gets to decide the question.

The case came before the Supreme Court after several lower courts overturned state bans on gay marriage. A federal appeals court had previously ruled in favor of the state bans, with Judge Jeffrey Sutton of the Sixth Circuit U.S. Court of Appeals writing a majority opinion in line with the rationale that the issue should be decided through the political process, not the courts.

14 couples

Fourteen couples and two widowers challenged the bans. Attorneys Mary Bonauto and Doug Hallward-Driemeier presented their case before the Court, arguing that the freedom to marry is a fundamental right for all people and should not be left to popular vote.

Three years after Obama first voiced his support for gay couples' right to marry, his administration supported the same sex couples at the Supreme Court.

"Gay and lesbian people are equal," Solicitor General Donald B. Verrilli Jr. told the justices at the oral arguments earlier this year. "It is simply untenable -- untenable -- to suggest that they can be denied the right of equal participation in an institution of marriage, or that they can be required to wait until the majority decides that it is ready to treat gay and lesbian people as equals.

Obergefell, the lead plaintiff in the case, married his spouse John Arthur in 2013 months before Arthur died.

The couple, who lived in Ohio, had to travel to Maryland aboard a medical jet to get married when Arthur became gravely ill. And when Arthur died, Obergefell began to fight to be recognized as Arthur's spouse on his death certificate.

The plaintiffs from Michigan are April DeBoer and Jayne Rowse , two Detroit-area nurses who are also foster parents. They took to the courts after they took in four special-needs newborns who were either abandoned or surrendered at birth, but could not jointly adopt the children because Michigan's adoption code requires that couples be married to adopt.

Sgt. Ijpe Dekoe and Thomas Kostura became plaintiffs in the gay marriage case after they moved to Tennessee from New York.

The pair had married in New York in 2011, but Dekoe's position in the Army took the couple to Tennessee, which banned gay marriage and refused to recognize gay marriages performed in other states.

2016

Candidates running closer to the center, including former Florida Gov. Jeb Bush and South Carolina Sen. Lindsey Graham, issued tightly-parsed language urging their colleagues to focus on protecting "religious freedom". And Ohio Gov. John Kasich urged Republicans to respect the ruling and ditch the matter altogether.

"In a country as diverse as ours, good people who have opposing views should be able to live side by side. It is now crucial that as a country we protect religious freedom and the right of conscience and also not discriminate," Bush said in his statement.

But conservative firebrands, including Louisiana Gov. Bobby Jindal and former Arkansas Gov. Mike Huckabee, said that conservatives must stand and fight by seeking a constitutional amendment banning gay marriage.

"I will not acquiesce to an imperial court any more than our founders acquiesced to an imperial British monarch. We must resist and reject judicial tyranny, not retreat," Huckabee said in a statement.

Democrats had no problem reacting, jumping fast on Twitter to express their universal elation.

Former Secretary of State Hillary Clinton said she was "proud" of the ruling and former Maryland Gov. Martin O'Malley tweeted a photo of the family at the center of his state's efforts to legalize gay marriage.