Prosecutors in Brian Fanion’s murder trial allege the former detective from Westfield, Mass., murdered his wife Amy, then staged her death to look like a suicide, just so he could keep his cop pension and be with his lover.

Fanion is accused of shooting his wife dead with his service gun while he was home for a lunch break in May 2018. During an investigation, cops first believed Amy died of a self-inflicted gunshot wound.

But forensic experts thought otherwise, stating the trajectory of the bullet ruled out the death as suicide, said assistant district, Mary Sandstrom, after Fanion was charged with first-degree murder on Wednesday, as reported by MassLive.

Sandstrom told the court the investigation unearthed an affair Fanion was having with another woman, and he feared losing half his pension if Amy divorced him.

The prosecutor said Fanion began the affair two months prior to his wife’s murder. She said Google searches on the suspect’s computer included divorce impact on one’s pension.

Sandstrom said Fanion was looking for apartments hours prior to Amy’s murder. Fanion’s lawyer, Jeffrey Brown, argued the ex-cop wasn’t having an affair and noted Amy’s struggles with depression.

Brown told the court Fanion had the support of the two children he had with Amy, along with her family.

Fanion is currently behind bars without bail. He’s scheduled to appear in court in January.