Setting the stage for its most significant ruling on gay rights, the U.S. Supreme Court said Friday that it would resolve the two-decade legal battle over same-sex marriage.

The justices agreed to hear cases from Michigan, Kentucky, Ohio and Tennessee, where state officials are defending laws that limit marriage to a man and a woman. The court set aside 2½ hours of arguments in April – compared with the usual hourlong session – with a decision expected by the end of June.

The outcome could be a landmark ruling giving gay and lesbian couples a right to marry nationwide under the Constitution’s protections for individual liberty and equal treatment.

In an order released Friday, the court said it would decide two civil rights questions that have deeply divided Americans: Does the 14th Amendment include a right to marry for same-sex couples, and must states recognize same-sex marriages that took place in other states?

The issue “is coming to the court at the right time and the right circumstances,” said Mary Bonauto, a Boston-based attorney who won the first state ruling for gay marriage, in Massachusetts in 2003.

The timing is no accident. The justices, both liberal and conservative, have long been wary of rulings that upset the settled expectations of the American public. The court didn’t protect interracial marriage until 1967, long after most states had already it.

SOCIAL CHANGE STRATEGY

Likewise, the justices opted in recent years to avoid ruling directly on gay marriage, giving more time for the idea to be accepted and legalized by individual states.

By taking the case now, the justices put themselves in position to ratify a profound social change that they helped set in motion, but which they did not anticipate would occur so quickly.

Opinion polls in the last year have shown that a solid majority of Americans support a right to marry for same-sex couples. Currently, gay marriage is legal in 36 states and the District of Columbia, a product of political decisions and judicial rulings.

Evan Wolfson, president of Freedom to Marry, a gay marriage advocacy group, said the court’s “decision today begins what we hope will be the last chapter in our campaign to win marriage nationwide.”

Early in 2008, no state recognized same-sex marriages except Massachusetts. And voters, including those in California, had consistently opposed changing the marriage laws to legalize same-sex unions.

But the tide of public opinion shifted.

Two years ago, the high court carefully sidestepped a ruling on the constitutionality of gay marriage when it struck down a key provision of the federal Defense of Marriage Act and allowed California’s Proposition 8, which banned same-sex unions, to be overturned.

In October, the justices surprised many by again avoiding the issue, declining to hear appeals of state same-sex marriage bans that had been voided as unconstitutional by several federal appeals courts.

But when the 6th U.S. Circuit Court of Appeals a month later upheld state bans of gay marriage in the four states, the high court was left with little choice but to resolve the dispute.

U.S. Attorney General Eric H. Holder Jr. said the Obama administration would urge the court to “make marriage equality a reality for all Americans.”

Gay rights advocates are reasonably confident they have the five-justice majority they need for victory, thanks to Justice Anthony M. Kennedy. Although he often votes with the four conservatives, he has written the court’s three most important opinions in favor of gay rights.

His 2013 opinion striking down the Defense of Marriage Act provision was cited repeatedly by judges who ruled against state laws forbidding same-sex marriage. Kennedy was joined then by liberal Justices Ruth Bader Ginsburg, Stephen G. Breyer, Sonia Sotomayor and Elena Kagan.

In recent months, the high court has hinted that the majority is ready to endorse gay marriage. When state officials filed emergency pleas that sought to block rulings that called for issuing marriage licenses to gay couples, those appeals were turned down. Only Justices Antonin Scalia and Clarence Thomas dissented.

MICHIGAN’S ARGUMENT

The silent assent from Chief Justice John G. Roberts Jr. and Justice Samuel A. Alito Jr. suggested that they no longer saw the prospect of a court majority upholding a state’s ban on same-sex marriage.

But Michigan’s lawyers are hoping they have an argument that could force Kennedy to think twice. Last year, Kennedy spoke for the court in upholding a state ballot measure that prohibited racial affirmative action in the state’s colleges and universities. He said then that the voters could be trusted to decide sensitive questions of public policy.

In defending their ban on same-sex marriage, Michigan’s lawyers say the state’s voters opted to preserve the traditional definition of marriage, and so Kennedy and the court should uphold their decision.

The cases to be heard in April feature several couples who have lived together for years.

The Michigan case, DeBoer vs. Snyder, was brought by April DeBoer and Jayne Rowse, who are both nurses. They have been a couple for 10 years and are raising four foster children. Under Michigan law, they may not jointly adopt the children because they are not married, and they may not marry because same-sex unions are illegal.

They sued in federal court, and after a nine-day trial, a federal judge struck down the state’s ban on same-sex marriage.

Gov. Rick Snyder appealed. “Same-sex marriage does not qualify as a fundamental right,” he argued in court papers, “because it is not deeply rooted in our nation’s history.”

In November, the 6th Circuit agreed. Judge Jeffrey Sutton said the decision whether to change the state’s marriage laws should be made by voters and elected officials, not courts. That ruling upheld the marriage laws in the four states and triggered the high court’s move on Friday.