A 100-year-old Bronx man accidentally shot himself with an illegal gun on Thursday, according to police sources.

Pedro Detres, born in March of 1917, was handling his .32-caliber revolver at his E. 162nd Street apartment just after 12:30 p.m. when the six-shooter went off, blasting him in his left thigh, he told police, according to sources.

The gun was not purchased legally — or recently, a police source said.

“He just said he obtained it many, many years ago. God knows how long ago that was,” the source said.

The centenarian Detres was taken to Lincoln Hospital, where he was arrested on charges of criminal weapon possession. He was later released without bail.