HARTFORD, Conn. — A divided Connecticut Supreme Court Friday reinstated the murder conviction of Kennedy cousin Michael Skakel, rejecting a Superior Court judge’s finding that Skakel’s trial was tainted by ineffective lawyering and setting the stage for Skakel’s return to prison after three years of freedom.

“Because we conclude that the petitioner’s trial counsel rendered constitutionally adequate representation, we reverse the judgment” of the lower court, a 4-3 majority of the Supreme Court wrote in a decision released Friday afternoon.

Skakel was convicted in 2002 in the bludgeoning death 27 years earlier of Greenwich neighbor Martha Moxley, when she and Skakel were both 15. The case has generated headlines for four decades because of Skakel’s Kennedy connection — he is a nephew of Robert F. Kennedy’s widow, Ethel — and the window the case provided into the privileged lives of Greenwich’s monied residents.

Skakel received a sentence of 20 years to life. But his conviction was overturned in 2013 after a Superior Court judge declared that Skakel’s defense attorney had botched the case.

“The defense of a serious felony prosecution requires attention to detail, an energetic investigation and a coherent plan of defense capably executed,” Judge Thomas Bishop wrote in October 2013. “Trial counsel’s failures in each of these areas of representation were significant and, ultimately, fatal to a constitutionally adequate defense.”

A month later, Skakel was out on bail. And the state began an effort to put him back behind bars, ultimately filing a 249-page appeal refuting Bishop’s conclusion that Skakel’s conviction was marred by ineffective assistance of counsel by lawyer Mickey Sherman. They said Bishop’s conclusions amounted to second-guessing Sherman’s reasoned defense strategy.

As an example, Skakel’s appellate attorney, Hubert Santos, had successfully argued that Sherman made a tactical error in failing to suggest that the killing might have been carried out by Skakel’s brother, who was once a suspect in the case. Sherman did present evidence about another possible killer — a family tutor — and testified that he made a strategic decision to focus on only one alternate suspect.

The state argued that while there may be differences of opinion on the best strategy, Sherman’s calculated choice couldn’t be seen as ineffective lawyering.

“At trial, they presented a defense based on a three-fold strategy: attacking the state’s evidence; presenting an alibi, and presenting a third-party culprit defense,” prosecutors wrote in their appeal. “This strategy failed not because of any fault of defense counsel, but because of the strength of the state’s case.”

The Supreme Court ruled Friday that Sherman’s decision not to focus on Thomas Skakel “was a reasonable strategic decision made after adequate investigation.”

In arguments before the high court last February, state prosecutors found themselves defending their former courtroom adversary, telling the justices that Sherman prevailed on a number of pretrial motions and sought the advice of top legal minds, including F. Lee Bailey and Barry Scheck.

“This was far from a slipshod defense,” Assistant State’s Attorney Susan Gill said during the hearing. “This was a well-thought-out, well-planned defense.”

Moxley was killed the night before Halloween in 1975 in the driveway of her Greenwich home. She was hit in the head repeatedly with a golf club belonging to the Skakel family, and then stabbed in the neck with the broken-off handle.

No forensic evidence ties Skakel to the crime, but more than two decades after the killing, Skakel was charged, based on incriminating statements he allegedly made to prep school classmates and inconsistencies in the alibi he gave police in the weeks after the killing.