A suspected stalker armed with a rifle hid at his ex-girlfriend's home in the rolling farmland of southern Pennsylvania and ambushed police officers who came to arrest him, killing three of them, a prosecutor said Thursday

Police arriving at the scene at about 2:10 p.m. Wednesday noticed the door to the home was unlocked even though the ex-girlfriend and her mother had locked it before leaving the property for their safety.

They opened the door and were immediately fired upon by the suspect, 24-year-old Matthew James Ruth, who was carrying an AR-style rifle with a suppressor, York County District Attorney Tim Barker said.

He said the suspect fired multiple rounds at the four officers at the door, killing three of them. A gunfight then ensued between Ruth and two officers outside. Ruth wounded a sheriff's deputy before police shot the gunman to death, Barker said.

Detective Sgt. Cody Becker, Detective Mark Baker and Detective Isaiah Emenheiser were the officers who were killed, he said. They all worked for the Northern York County Regional Police Department.

The violence erupted Wednesday afternoon as officers sought Ruth, who they believed had been at the property the night before. A woman he had briefly dated lived there. Her mother called police late Tuesday after she spotted a man wearing camouflage looking into the home with binoculars.

It was one of the state’s deadliest days for law enforcement this century, matching the toll from a day in 2009 when three officers were ambushed by a domestic violence suspect sporting a bulletproof vest.

AP video by Tassanee Vejpongsa