An Illinois State Police trooper was acquitted Wednesday of felony charges that he shot into his ex-girlfriend’s Southwest Side home two years ago, though a judge found him guilty of a lesser charge.

Juan Lopez, now 32, had been charged last July with home invasion and aggravated discharge of a firearm for the incident that happened the morning of April 6, 2014.

Cook County prosecutors alleged Lopez meant to harm the woman — also a trooper — whom he’d broken up with two weeks before he came to her home and fired six bullets into the rear sliding glass door and kitchen window.

Lopez testified that he “mistakenly” thought a crime was in progress when he saw a car in the driveway that he didn’t recognize, as well as damage to a side door, according to a statement from his attorney, Dan Herbert. Lopez went into the home with his gun when he heard a woman’s screams and saw a man he didn’t know in her bedroom, he testified.

After finding that the other man — another trooper — was not a burglar, Lopez stayed at the scene while the woman called 911. She was granted an emergency order of protection three days after the incident and was given a one-year order of protection against Lopez the following February, prosecutors said.

“Lopez’s belief turned out to be wrong but it was not unreasonable for him to have believed what he did and acted accordingly,” Herbert said.

He had been free after posting 10 percent of a $150,000 bond last summer, according to Cook County Circuit Court records. Judge James B. Linn found him not guilty Wednesday of four counts of home invasion and three counts aggravated discharge of a firearm, but Lopez was convicted of a misdemeanor count of reckless conduct and sentenced to court supervision.

Lopez, of the 1600 block of South Throop, was placed on administrative leave without pay from ISP after being charged.

“He hopes he can return to the job he loves soon,” Herbert said.