James R Leavelle, the detective who was handcuffed to Lee Harvey Oswald when the killer of John F Kennedy was in turn shot dead by Jack Ruby, has died. He was 99.

Leavelle’s daughter, Karla Leavelle, confirmed her father’s death to the New York Times.

Kennedy was shot dead on 22 November 1963, as he passed through Dallas.

Reporting for the Guardian, Alistair Cooke wrote: “The motorcade was going along slowly but smoothly when three muffled shots, which the crowd first mistook for fireworks, cracked through the cheers. One hit the shoulder blade and the wrist of Governor [John] Connally [of Texas] who was taken with the president to the hospital, where his condition is serious.

“The other brought blood trickling from the temple of the sitting president. His right arm flopped from a high wave of greeting and he collapsed into the arms of Mrs Kennedy, who fell unharmed. She was heard to cry ‘Oh no’ and sat there all the way cradling his head in her lap.”

Kennedy was declared dead at Parkland Hospital.

Jim Leavelle pictured in 2017. Photograph: Devon Ravine/AP

Two days later Oswald, then a suspect in the shooting of a police officer but not yet formally tied to the murder of the president, was led through the basement of a Dallas police station. Ruby, a nightclub owner who has long been rumoured to have had ties to the Mob, lunged forward and shot him.

A Dallas Times Herald photographer, Bob Jackson, captured the flash of the moment, the burly, Stetson-hatted Leavelle recoiling from the shot, Oswald crumpled by it, Ruby lunging forward with his pistol clearly visible. The image won a Pulitzer Prize.

The Times reported that Leavelle often discussed an exchange with Oswald shortly before the assassin himself was assassinated.

“Lee,” Leavelle said in the version of the story quoted by the Times, “if anybody shoots at you, I hope they are as good a shot as you.”

Oswald, he said, replied: “You’re being melodramatic.”

In 2013, Leavelle told the New York Daily News Oswald said “Nobody’s gonna shoot at me”.

“Famous last words,” Leavelle said.

In 2006, Leavelle told the Times that after his exchange with his prisoner, he saw “out of the corner of my eye” that Ruby “had a pistol by his side”.

“I jerked back on Oswald to get him behind me,” he said. “I had my hand through his belt. All I succeeded in doing, I turned him so instead of dead centre the bullet hit four inches to the left of his navel and two inches above.”

Oswald was declared dead in the same hospital as Kennedy. Ruby received the death penalty but died before sentence could be carried out.

In 2017, files declassified by order of President Donald Trump showed that the night before the shooting, the FBI received a call about a plot to kill Oswald in Dallas.

In a memo written on 24 November, the day of Oswald’s death, then FBI director J Edgar Hoover said: “We at once notified the chief of police and he assured us Oswald would be given sufficient protection. This morning we called the chief of police again warning of the possibility of some effort against Oswald and again he assured us adequate protection would be given.

“However, this was not done.”

Leavelle served in the US navy in the second world war, surviving the attack on Pearl Harbor before sustaining an injury at sea. He had a long career in law enforcement and opened a polygraph company in retirement.

The suit, tie and hat he wore on the day he became part of American history, and the handcuffs he used, have been displayed at the Sixth Floor Museum at Dealey Plaza, in the former Texas School Book Depository from which Oswald shot the president.