Boston police arrested a teen outside Dorchester District Court after he failed to follow their instructions and was later found to have a gun, authorities said.

Around 2:15 p.m. on Monday, officers responded to a report of a man with a gun near the Dorchester District Court at 510 Washington St., police reported. Upon arrival, police located the individual matching the suspect’s description.

RELATED: Daytime Dorchester shooting leaves one dead, another injured

Authorities, with their firearms drawn, began giving instructions to Raughn Williams, 18, of Boston, who did not comply with their directions to show his hands, police stated. Instead, Williams allegedly responded, “Why?” and paced back and forth while holding the front of his waistband with his right hand.

After two minutes, Williams got down on his right knee and officers quickly moved in and handcuffed him, authorities said, adding that he had earlier threatened to shoot one of his family members. A search of the suspect revealed a firearm in his right pocket.

RELATED: Dorchester man threatens police with fake gun: BPD

"That kid’s lucky he didn’t get shot," an unnamed officer said at the scene.

Williams was charged with unlawful possession of a firearm, ammunition possession, carrying a loaded firearm on a public way and assault by means of a dangerous weapon, authorities added.