WALTERBORO, S.C. — After five weeks of trial, the murder case against Alex Murdaugh narrowed on Friday to the question of what happened in a critical few minutes after the prominent South Carolina lawyer went down to his family’s dog kennels where his wife and son were found shot to death later that night.

On the second and final day of Mr. Murdaugh’s crucial testimony in his own defense, prosecutors aggressively challenged him about those key minutes, showing that his new account of his movements that night — offered this week after more than 20 months of denying he was at the kennels at all — is difficult to reconcile with the timeline of the murders.

Armed with telephone calls, texts, videos, car navigation data and cellphone step counts, the lead prosecutor, Creighton Waters, showed that Mr. Murdaugh would have had to have left the kennels and returned to the house a short distance away only minutes before the killings — despite his claims that he had heard no gunshots.

Mr. Murdaugh had initially told the police that he had been napping in the house, but he told a different story on the witness stand this week after a video emerged showing that he had indeed been present at some point when his wife and son were out checking on the dogs.

In his own account, Mr. Murdaugh said he drove a golf cart down to the kennels and spoke briefly with his wife, but headed back to the house alone a few minutes later. About two minutes after he said he left, the phones of both victims — Paul Murdaugh, 22, and Maggie Murdaugh, 52 — were locked and were never unlocked again, suggesting that they were killed around then.

“Does that sound like real life to you, that you jet there and jet back?” Mr. Waters asked, one of many questions that attempted to paint Mr. Murdaugh’s chronology as absurd.

He emphasized that Mr. Murdaugh had not admitted to being at the kennels until the crucial video, shot by his son Paul that night, emerged in court.

“You had to sit in this courtroom and hear your family and your friends, one after the other, come in and testify that you were on that kennel video, so you — like you’ve done so many times over the course of your life — had to back up and make a new story that kind of fit with the facts that can’t be denied,” he said. “Isn’t that true, sir?”

“No, sir, that’s not true,” Mr. Murdaugh replied.

Mr. Waters used cellphone and other data to suggest that Mr. Murdaugh had set about creating an alibi after fatally shooting his wife and son — driving to visit his ailing mother, who lived about 15 minutes away, and making a series of phone calls to friends and relatives on the way there and back.

Mr. Murdaugh maintained his own theory of the crimes, saying on Friday that he has always believed that his son was targeted as a result of his involvement in a fatal boat wreck in 2019. Paul Murdaugh had been accused of crashing the boat while drunk, killing one of the passengers. Alex Murdaugh said he believed that someone could have committed the attacks in response to vitriolic articles and online comments that villainized his son.

“I believed then and I believe today that the wrong person saw and read that,” he said. “Because I can tell you for a fact that the person or people who did what I saw on June 7, they hated Paul Murdaugh and they had anger in their heart.”

He added, using a nickname for his son: “And that is the only, only reason that somebody could be mad at PawPaw like that and hate him like that.”

Prosecutors have argued that Mr. Murdaugh killed his son with two shotgun blasts before turning a rifle on his wife, shooting her several times. They say investigations into his finances were about to expose that he had embezzled millions of dollars over many years, in part to pay for his addiction to painkillers, and that he murdered his family in an effort to gain sympathy and halt the inquiries into his finances.

Mr. Murdaugh said that the financial problems he was having would never lead him to harm his family. He tearfully apologized for his initial lie about being at the kennels, saying he had held back the truth because he was paranoid about being considered a suspect, a fear he said was fueled by the painkiller addiction.

He also admitted on the stand that he had stolen millions of dollars from settlements meant for his clients, as well as from his law firm, stealing $3.7 million in 2019 alone. At the same time, he was making hundreds of thousands of dollars each year in genuine income from his law firm, where he worked as a personal injury lawyer.

A key theme in Friday’s cross-examination was that Mr. Murdaugh’s own extensive experience as a lawyer — who had also volunteered with the local prosecutor’s office — enabled him to help hide his crime.

He was intimately familiar, Mr. Waters said, with the kind of call logs, car data and other evidence that prosecutors were now using to try to convict him.

Legal observers said that it was always risky for a defendant to testify, and that Mr. Murdaugh’s testimony could easily have backfired with the jury. Tyler D. Bailey, a lawyer in Columbia, S.C., said Mr. Murdaugh had seemingly made a “calculated bet” in testifying about the events.

“Alex needed to get on the stand to tell his story to the jury,” Mr. Bailey said. He said Mr. Murdaugh had been trying to “redeem his credibility and tell the jury himself that just because he’s stolen from countless people doesn’t mean he killed his son and wife.”

A murder conviction carries a minimum of 30 years in prison in South Carolina, and prosecutors have said they will seek to have him imprisoned for life without the possibility of parole. The trial was expected to wrap up by the middle of next week after a month of testimony and more than 70 witnesses.

In concluding Mr. Murdaugh’s testimony Friday afternoon, his lawyer, Jim Griffin, returned to his central defense, asking him directly whether he had killed either his wife or son. Mr. Murdaugh said that even if he had feared, in 2021, that his embezzlement was about to come to light — something he says is not true — he would have rather hurt himself than his family.

“I can promise you I would hurt myself before I would hurt one of them,” he said. “Without a doubt.”

Reporting was contributed by Jesus Jiménez and Ben Shpigel.