A former Pennsylvania state trooper who caused the deaths of his pregnant wife and the child she was carrying in what he characterized as a gun-cleaning accident at their home has pleaded guilty to criminal charges.

Joseph Paul Miller pleaded guilty Thursday to two counts of involuntary manslaughter for causing the March 2014 deaths of JoAnna Miller and the baby girl, who was delivered but died soon after.

Miller, of Horsham, initially said the gun was about 10 feet away from his wife when it accidentally went off, but he later revised that distance to about 2 feet away. Prosecutors in suburban Philadelphia, however, said ballistics and forensics tests showed the gun was only 3 to 6 inches from his wife’s head when it fired, and they charged him.

Miller, who’s 36, faces up to five to 10 years in prison when sentenced in the coming months.

He has resigned from the state police and maintains custody of the couple’s other children, said his attorney, Tim Woodward.

“He’s devastated, and not a day goes by that he doesn’t miss his wife,” Woodward said in a phone interview. “This is an unspeakable tragedy, the consequences of which will remain with Joe the rest of his life.”

JoAnna Miller, who was 34, had been 24 weeks pregnant when she was shot in the head in their family room while going through children’s clothes to donate them. She delivered the baby, named Gillian, through an emergency C-section. Mother and daughter died soon after.

Joseph Miller told investigators he had been taking apart a gun he owned in the family room to clean it when it discharged. In a 911 call he said: “I, ah, was cleaning. I was about to clean my gun, and I didn’t realize there was a round … I shot my wife.”

Miller remains out on bail while he waits to be sentenced in Montgomery County.