The men had been killed several days earlier, sometime between the night of Aug. 21 and the morning of Aug. 22, investigators determined.

Mr. McFarland, the affidavit says, had been released from prison on Aug. 20. He had been arrested on Aug. 22 within hours of the murders after he was accused of using a knife in a sexual assault about a mile away in New Haven.

That led detectives to interview him in prison that September. He denied any role in the Hamden killings.

The police chased other leads. A local woman told them she had been in the condo on the night of the murders with two men who she said were the killers. Both denied being involved. (One has since died, as has the woman who implicated him. DNA evidence cleared the second man this year.)

Then, in August 1996, Mr. McFarland contacted the Hamden police, the affidavit says. He said he wanted to confess because he had “found religion and was dying of H.I.V.”

In several statements over the next few months, the affidavit says, he recounted “his connection to the victims, entrance to the home, the torturing purpose of the shallow chest wounds and the near-decapitation of both victims.”

Captain Smith, who took Mr. McFarland’s confession, said that “he told us approximately 30 things that you would have had to be there to know.”