The deputy who was hospitalized after being shot in the stomach during a confrontation with an allegedly armed man in Long Beach last week was struck by his partner's gun, the Los Angeles County Sheriff's Department said Thursday.

The deputy was shot when trying to arrest 23-year-old Noel Aguilar on May 26 in Long Beach, officials said. It was not clear who had control of the other deputy's gun at the time of the shooting.

Breaking News Alerts: Download the NBCLA News App

Aguilar was shot and killed by deputies after he allegedly fought with them and tried to take one of their guns during a confrontation in Long Beach, officials said.

An investigation revealed the deputy was struck by a bullet fired by the other deputy's gun, the LASD said Thursday.

The shooting happened near Long Beach Boulevard and East 69th Way in Long Beach, about 15 miles south of downtown Los Angeles, where witnesses reported hearing several rounds of gunfire.

It followed a traffic stop in Compton that turned into a foot pursuit involving two deputies and Aguilar, who was allegedly armed with a semi-automatic gun, officials said.

The injured deputy underwent surgery and is recovering at home, officials said. The case remains under investigation.

Correction: An earlier version of this article stated the deputy was struck by his partner's gunfire. During an interview, an LASD spokesperson said it was not clear who was in control of the deputy's gun when shots were fired.