The man who fired 15 times at his probation officers inside his Billings home in 2018 was given the maximum prison term Tuesday.

Michael Jeffrey Anderson, 62, was sentenced to 40 years in the Montana State Prison, as prosecutors had sought.

Yellowstone County District Judge Donald Harris also imposed a 20-year parole restriction.

Defense attorney Joel Thompson had asked for 40 years in prison with 20 suspended.

Anderson fired a semiautomatic handgun at Probation and Parole officers Derek Skinner and Allan Kitterman during a routine home check on May 1, 2018. Anderson fired 15 times, according to Yellowstone County Attorney Scott Twito.

The two officers fired back as they fled out the front door of the house, and a two-hour standoff with the Billings Police Department’s SWAT team ensued.

The incident “was basically an ambush,” said Harris, the judge. “And it’s just a miracle people weren’t killed.”

Roughly two dozen members from the Department of Corrections Probation and Parole Division attended the sentencing, including Skinner and Kitterman. Neither chose to testify and instead a supervisor for the office, Candace Reinschmidt, spoke on their behalf.

Reinschmidt said probation and parole officers are aware of the risk of violence in their line of work — “And this just really drove it home.”

Anderson had seen no major problems on supervision until the day he fired at officers, Reinschmidt said. Before the gunfire, officers noticed minor violations, such as alcohol and a BB gun in the house.

More worrisome violations, Reinschmidt said, were the guns “numbering in the double digits hidden throughout his apartment,” and the surveillance system outside Anderson’s house officers noticed earlier in the day on their first, unsuccessful attempt to reach him at home.

Kitterman had been supervising Anderson on probation for roughly a year before the shooting. That day was the first time he had visited Anderson at home.

Anderson’s criminal history included an assault on a peace officer and a federal conviction for possessing a machine gun.

At the time of the shooting, Anderson had been on supervision for stabbing a bystander who tried to intervene in a fight between Anderson and his girlfriend in the parking lot of a Bozeman coffee shop in 2007.

Prosecutors originally charged Anderson with two counts of attempted deliberate homicide but later reduced those charges to assault with a weapon.

Harris said he didn’t believe Anderson would change and become less of a danger to the community, citing his history of violence and the fact that he was amassing firearms while on supervision.

Thompson, the defense attorney, said Anderson had long suffered from opioid addiction due to chronic pain and had turned to meth to cope with the opioid withdrawal symptoms. On the day he shot at officers, he had been awake for six days.

Thompson said his client made “a horrible decision,” but that it was not the “diabolical rationality” viewed by prosecutors.

“Murderous intent? I say no,” Thompson said. “It’s probably better explained by some kind of a psychosis that he was under” from the drugs and sleep deprivation.

Thompson said his client understands that he caused a traumatic experience for the officers.

“He has read their letters and statements, and never disputed the effect this must have had on all those who were doing their job,” Thompson said.

Anderson has been a “clear conduct inmate” in jail, he added, despite being in lockdown 23 hours a day and in continuous physical pain.

Anderson has been held at the jail on $750,000 bond since his release from the hospital two days after the shooting. A bullet lodged in Anderson’s lower back during the incident, Thompson said.

When it was his turn to speak, Anderson referred to Kitterman and Skinner as “two gentlemen” who work in the community.

“There’s not a day that goes by that I don’t think about this and wish that there was some way that I could relive it and take it back, and do things differently,” Anderson said, in a level voice. “I know that it’s affected them for the rest of their life, what I did that day. And I just can’t express upon you, or come up with the words or terminology that — I am so sorry.”

Anderson was ordered to pay $8,630.77 in restitution for damage to his rental home during the shooting.