(KRON) — An armed security guard was attacked when he attempted to stop a suspected shoplifter from leaving a Home Depot store in San Carlos. The violent confrontation escalated until the guard shot the suspected thief, the San Mateo County Sheriff’s Office said.

The incident happened at 10 p.m. Monday at a Home Depot located at 1125 Old County Road.

“Store employees confronted suspect Jonathan Mackey on suspicion of shoplifting, resulting in a physical confrontation,” Sheriff’s Sgt. Javier Acosta wrote. “During the altercation, Mackey managed to gain control of a security guard’s ASP collapsible baton.”

Mackey, 26, of San Carlos, used the baton to strike the security guard in the head and face, according to the Sheriff’s Office.

After he beat the guard, Mackey threw the baton through a glass window near the store’s entrance, according to Acosta. The guard fired two shots at Mackey, striking him with at least one bullet, investigators said.

“A San Mateo County Sheriff’s Deputy, who was assigned to the San Carlos Patrol Bureau and happened to be in the vicinity, heard the shots, and quickly responded,” Acosta wrote.

The deputy detained and arrested Mackey. Backup law enforcement officers and paramedics arrived at the scene to give medical aid to the shot man and the security guard.

Mackey and the guard suffered non-life threatening inquires. Mackey was booked into a San Mateo County jail on robbery and assault charges. His first court appearance is set for Wednesday at 1:30 p.m.