A divided Supreme Court ruled Thursday that a federal program regulating the registration of sex offenders is constitutional.

The case split the court, took months to decide and was closely watched not because of the Maryland offender at its center but because it raised questions about how much authority Congress can cede to the executive branch — in this case the attorney general.

More than the fate of a specific federal program, the decision seemed to portend major battles over conservative concerns about the “administrative state” and whether executive agencies and unelected public officials have been given too much power.

The case was one of the first argued in October, when the court’s current term began, and was decided in its closing days in a 5-to-3 ruling. And there were indications it would have come out differently if it had been considered after Justice Brett M. Kavanaugh joined the court and there were a full bench.

The court was split 4 to 4 on the question, and Justice Samuel A. Alito Jr. said he joined the court’s liberals to make a majority only because of how the court had ruled on such questions in the past. He did not endorse their reasoning.

“If a majority of this court were willing to reconsider the approach we have taken for the past 84 years, I would support that effort,” Alito wrote. “But because a majority is not willing to do that, it would be freakish to single out the provision at issue here for special treatment.”

Justice Elena Kagan, writing for the plurality, said her conservative colleagues were close to making a mountain out of a molehill in examining the Sex Offender Registration and Notification Act (SORNA).

“If SORNA’s delegation is unconstitutional, then most of Government is unconstitutional — dependent as Congress is on the need to give discretion to executive officials to implement its programs,” Kagan wrote.

The case was brought by Herman Avery Gundy, who in 2005 pleaded guilty in Maryland to sexual assault of a minor. After his release from prison, Gundy was arrested and convicted of failing to register with local authorities in New York as required under SORNA.

The federal law was enacted after his 2005 conviction, but it allowed the attorney general to decide the rules for those like Gundy. His lawyers at the Supreme Court said it gave the attorney general power both to write the law and enforce it.

To preserve separation of powers, the court has decided in the past that Congress may not cede its authority to the executive branch without supplying “intelligible principles.”

Kagan said the standard was met and that Congress intended for the attorney general to set up a system for sweeping in those past offenders such as Gundy.

“That statutory authority, as compared to the delegations we have upheld in the past, is distinctly small-bore,” Kagan wrote. “It falls well within constitutional bounds.”

She noted the nondelegation doctrine has been invoked by the court only twice — and that both times were in 1935.

“By contrast, we have over and over upheld even very broad delegations,” she wrote. Kagan was joined by fellow liberal justices Ruth Bader Ginsburg, Stephen G. Breyer and Sonia Sotomayor.

Justice Neil M. Gorsuch, who has made separation of powers issues a high concern in his short time on the court, answered with a dissent nearly twice as long as Kagan’s opinion.

“If the separation of powers means anything, it must mean that Congress cannot give the executive branch a blank check to write a code of conduct governing private conduct for a half-million people,” Gorsuch wrote. He was joined by Chief Justice John G. Roberts Jr. and Justice Clarence Thomas.

Gorsuch said it would be “easy enough to let this case go” because sex offenders “are one of the most disfavored groups in our society.”

“But if a single executive branch official can write laws restricting the liberty of this group of persons, what does that mean for the next?” he asked.

Gorsuch said he welcomes the next case raising the issue.

“In a future case with a full panel, I remain hopeful that the court may yet recognize that, while Congress can enlist considerable assistance from the executive branch in filling up details and finding facts, it may never hand off to the nation’s chief prosecutor the power to write his own criminal code,” he wrote.

The case is Gundy v. United States.