The gun used by a Mexican illegal immigrant when he allegedly shot and killed a 32-year-old woman at a San Francisco pier belonged to a federal agent, a source confirmed to Fox News Tuesday.

It was not immediately clear how Francisco Sanchez, 45, would have obtained the weapon. However, the San Francisco Chronicle reported sources told the paper the gun had been stolen during a car burglary in June.

Earlier Tuesday, Sanchez pleaded not guilty to first-degree murder in last week's shooting of Kathryn Steinle, 32, while she was walking with her father and a family friend at Pier 14. Police said witnesses heard no argument or dispute before the shooting, suggesting it was a random attack.

Sanchez had previously told KGO-TV Sunday in a mix of Spanish and English that he found a gun wrapped inside a shirt while he was sitting on a bench at the pier and smoking a cigarette.

"So I picked it up and ... it started to fire on its own," Sanchez said, adding that he heard three shots go off.

A source familiar with the investigation told the San Francisco Chronicle that Sanchez said he was at the popular pier to shoot at sea lions, and discarded the firearm after realizing he had shot Steinle.