Boston police have accused a Randolph man of illegally possessing a loaded gun found in the waistband of his pants and trying to attack officers who were arresting him.

Derek Lima, 27, was charged with unlawful possession of a firearm as a subsequent offense, unlawful possession of ammunition, carrying a loaded firearm, possession of a firearm with a destroyed serial number and assault and battery on a police officer. Police said this his third time unlawfully possessing a gun. He is expected to be arraigned in Dorchester District Court Wednesday.

Police said they found Lima the night of June 11 in the Dorchester neighborhood of Boston after responding to a call about someone with a gun. Police said Lima had a pistol in his waist band and was arrested. Lima tried to kick an officer and spit in their face while in the back of a police cruiser, according to police.