A former cabdriver who nearly killed an Alexandria police officer has been arrested in an unrelated case on arson and gun charges, months after his release from a Virginia mental hospital.

Kashif Bashir, 33, is accused of setting fires at two homes in Prince William County on Wednesday and carrying a firearm, something he is barred from doing after being found not guilty by reason of insanity in the 2013 shooting of Peter Laboy.

According to court filings, Bashir confessed a day before the fires to being “overly preoccupied” with his female therapist. On the day of the alleged arson, he admitted that he had not been taking his medication.

He has a preliminary hearing on March 8.

Bashir was held for treatment in a mental hospital after a judge concluded that he could not understand right from wrong when he shot Laboy. Bashir was required to undergo therapy and stay on antipsychotic prescriptions as a condition of his release last June after experts determined that he was capable of living on his own.

Alexandria Commonwealth’s Attorney Bryan Porter, who opposed Bashir’s release, filed a motion on Monday to return him to the mental hospital.

“In light of the facts of the underlying offense of this case, the origin of which was his fixation on a woman he planned to rape and his use of a firearm in the shooting of Officer Laboy, it is clear that his preoccupation with his therapist and his possession of a firearm render him dangerous and in need of hospitalization,” Porter wrote.

At the hearing last year, Porter argued that Bashir’s evaluators had not analyzed the sexual nature of his crimes.

According to trial testimony, on the day that Bashir shot Laboy, the then-27-year-old was intent on raping a young woman and was stalking her at an Old Town design shop where she worked. When the store owner alerted a police officer to Bashir’s strange behavior, Bashir took off in his cab. Laboy responded to a radio call for help and followed on his motorcycle. He stopped Bashir but was shot in the head. Bashir was caught several miles away after crashing into another vehicle, according to trial testimony.

Doctors at his 2014 trial testified that Bashir believed his brain was being reprogrammed and that he needed to commit robbery and rape and to shoot a police officer to help move toward a higher state of being.

Last year, experts at the mental hospital where Bashir was confined after his trial determined that he could live on his own. His release came with conditions: Stay on antipsychotic medication, see a team of therapists three times a week, not own or operate a motor vehicle, and remain within 50 miles of his Woodbridge apartment.

Bashir complied with the conditions through January, according to Porter’s motion, and his caretakers asked to modify the plan so he could seek a job. But a Feb. 4 report noted that Bashir had “demonstrated difficulties in maintaining professional boundaries with treatment providers.”

Laboy, who suffered a traumatic brain injury from which he has not fully recovered, also opposed the release out of concern that Bashir would acquire a gun.

“I’m glad he’s back in jail,” Laboy said Monday. “I said, ‘It’s going to happen sooner or later.’ ”