Dayna Murphy, left, and Shannon St. Germain pose on their wedding day. REUTERS/Mark Blinch The Supreme Court has just ruled that gay marriage is legal nationwide, in a huge victory for gay-rights advocates just a little over a decade after Massachusetts became the first state to legalize gay marriage.

Justice Anthony Kennedy issued the 5-4 ruling, finding that the Fourteenth Amendment — which guarantees "equal protection under the law" and the right to "due process of law" — requires a state to license a marriage between two people of the same sex.

"The nature of marriage is that, through its enduring bond, two persons can together find other freedoms, such as expression, intimacy, and spirituality," Kennedy wrote. "This is true for all persons, whatever their sexual orientation."

In his ruling, Kennedy expressed why marriage is necessary for true gay equality.

"As the state itself makes marriage all the more precious by the significance it attaches to it, exclusion from that status has the effect of teaching that gays and lesbians are unequal in important respects," he wrote in the ruling joined by the court's liberals, justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor, and Elena Kagan.

Later on in the opinion, Kennedy wrote, "Especially against a long history of disapproval of their relationships, this denial to same-sex couples of the right to marry works a grave and continuing harm."

Justice Anthony Kennedy has consistently voted for gay rights. The decision signifies a major advance in gay rights. It was just in 2003 that Kennedy wrote a majority opinion striking down Texas' sodomy law. Before 2004 no states recognized gay marriage, and that year many states went as far as banning same-sex marriage.

In his opinion, Kennedy also addressed the argument that voters should be allowed to decide gay marriage.

"Of course, the Constitution contemplates that democracy is the appropriate process for change, so long as that process does not abridge fundamental rights," he wrote.

Kennedy identified four principles that demonstrate why same-sex couples should have the right to marry.

1. The right to "personal choice regarding marriage is inherent in the concept of individual autonomy."

2. "The right to marry is fundamental because it supports a two-person union unlike any other in its importance to the committed individuals."

3. The right to marry "safeguards children and families and thus draws meaning from related rights of childrearing, procreation, and education."

4. Marriage is a "keystone of the nation's social order."

This was the second time America's high court took up same-sex marriage. The first time, in June 2013, Kennedy wrote the majority opinion striking down a key provision of the Defense of Marriage Act (DOMA), in a ruling that allowed the US government to recognize same-sex marriages in states where they were already legal.

But the court declined to rule on the broader question about gay marriage: Is there a constitutional right to gay marriage?

A gay pride flag being waved in front of the Supreme Court. Reuters/Lucy Nicholson The court's 2013 decision on DOMA has spawned battles across the country over same-sex marriage — including one in Alabama, where courts have issued conflicting rulings leading to an uncertain fate for gay couples.

That latest case reviewed a decision by the US Court of Appeals for the Sixth Circuit to uphold same-sex marriage bans in Michigan, Ohio, Tennessee, and Kentucky, and looked at whether those bans violated the Fourteenth Amendment.

In their petition asking the Supreme Court to hear the case, same-sex couples argued that Kentucky's same-sex marriage ban "marks the same-sex relationships and the families they create as less valuable and less worthy of respect than opposite-sex relationships."

That mark creates a stigma, the petition continued, that is "incompatible with the bedrock Constitutional principles animating the Fourteenth Amendment."