A Brooklyn police officer trying to shoot at a large dog accidentally shot his sergeant on Tuesday night when the bullet ricocheted off something and struck him, police said.

The officers were responding to a call of a loud argument between residents of the third and sixth floors inside a Brownsville apartment building on Kings Highway at about 10:40 p.m. when an "aggressive" pit bull came out into the hallway, police said.

One of the officers tried to shoot at the pit bull, but missed. The bullet grazed the dog, then ricocheted off something and struck the big toe of the sergeant, police said.

The dog was taken into custody of the ASPCA, and the sergeant was treated at Kings County Hospital.