Peter Laboy poses for a portrait photograph on a day when he was volunteering at the Alexandria Police Department on April 2. (Matt McClain/The Washington Post)

A cabdriver charged with shooting an Alexandria police officer was found not guilty by reason of insanity Thursday after a judge determined that the 29-year-old man could not understand right from wrong during the attack last year in the heart of Old Town.

Alexandria Circuit Court Judge James C. Clark said that the testimony of mental health experts, in particular, had convinced him that Kashif Bashir did not understand what he was doing when he shot Alexandria Officer Peter Laboy in the head. He said the experts were virtually unanimous in declaring that Bashir had long suffered from paranoid schizophrenia and that he was insane at the time of the shooting.

“To characterize this case as a tragedy, I would suggest, grossly understates the facts,” Clark said. “Having said that, I’ve got to deal with facts. I’ve got to deal with evidence.”

The judge ordered Bashir turned over to the custody of state mental health officials for further evaluation.

Laboy, who has made a miraculous recovery but is living with the effects of a traumatic brain injury, did not noticeably react as the verdict was read. The 46-year-old father of four declined to comment afterward, but he smiled and offered to help Commonwealth’s Attorney Bryan Porter carry boxes of evidence out of the courtroom.

Laboy’s wife, Suzanne, cried as supporters hugged her in the hallway. She said in an e-mail that the verdict was “not a complete surprise” but “still upsetting.”

Porter said afterward that Laboy’s reaction was “one of disappointment” and that it mirrored his own feelings. He said he hoped that the trial had provided some answers for the officer’s family.

“Obviously, I’m disappointed,” Porter said. “I wish we could have brought a conviction home in this case.”

Bashir’s trial this week was a somewhat unusual affair, as prosecutors and defense attorneys agreed that Bashir ambushed Laboy without provocation. Bashir had acted strangely in the Stuart Nordin Design shop in Old Town on Feb. 26, 2013, and he drove by again the next day when a police officer was inside talking to a store employee.

On Thursday, two psychologists who evaluated Bashir provided the chilling backdrop for those encounters, saying the cabdriver told them that a voice in his head had sent him to the design shop on a mission of terror. They said Bashir believed that his brain was being reprogrammed and that he needed to commit robbery and rape and to shoot a police officer to help him move toward some sort of higher state of being.

The doctors said Bashir initially intended to rape a worker at the shop when he went inside Feb. 26, but after she persuaded him to leave the store and locked the door, he did not carry out his plan. He drove back the next day with similar mayhem in mind and spotted a police officer inside, the doctors said.

After a worker in the store told the officer about Bashir’s strange behavior, the officer gestured for the cabbie to pull over, according to testimony at the trial. But Bashir took off. He was soon stopped by Laboy near Lyles-Crouch Traditional Academy.

According to testimony at the trial, Bashir shot Laboy before the motorcycle officer was able to fully dismount his bike. Bashir told doctors that he got out of his cab and fired one shot because a voice instructed him to and that he believed Laboy “would reappear elsewhere.”

Bashir eventually led other officers on a chase that ended when he crashed his cab in Fairfax County, according to trial testimony. The doctors said that throughout the incident Bashir did not understand what was happening. “He believed that something else entirely was taking place,” said forensic psychologist William Stejskal.

Porter did not dispute that Bashir suffered from mental illness, but he argued that the defendant “shaded” what he said to psychological evaluators to “conform with the insanity defense.” He noted that Bashir bought the gun he used to shoot Laboy the day before and that the gun shop’s employees saw nothing unusual in his demeanor.

Porter said that officers had interfered with Bashir’s plan to sexually assault a woman and that Laboy merely stood between him and escape. He called the cabdriver’s actions “so planned and predatory that they belie the term criminal insanity.”

Bashir’s defense attorneys had argued that their client suffered from “pervasive” mental illness that probably originated during a tumultuous childhood in Pakistan. Bashir’s sister, Humera Adil, for example, tearfully described at the trial how her brother, as a boy, had to douse his mother with water after she set herself on fire. She later died.

Porter said state mental health officials have 45 days to prepare a report about Bashir, and after that, prosecutors and defense attorneys will return to court to decide whether Bashir should be committed to a mental health institution or released with conditions. Porter said he will argue that Bashir be held in a secure facility. Bashir’s defense attorneys could not be reached for comment after the verdict.