A man was shot and wounded after three officers fired at him Sunday morning in Brooklyn, the NYPD said.

Witnesses told police that Paul Mathurin, 31, was waving a handgun and acting in an irrational manner in Prospect-Lefferts Gardens early Sunday. Mathurin was shot once in the right hip, after the officers fired 12 rounds at him, police said at a press conference following the incident. 

The shooting happened near Rogers and Sterling avenues around 7:20 a.m. after a gunshot activated the NYPD's ShotSpotter technology, which uses sensors to detect gunshots in parts of the city. Police said they also received calls about a shot fired. 

Cops said witnesses told them that Mathurin was showing his gun, screaming and acting in a menacing manner. When the officers approached him and asked him to stop, he did not, cops said.

The gun Mathurin had, a 9 mm, was recovered at the scene, the NYPD said.

Mathurin was taken to Kings County Hospital in stable condition, police said. The officers, all from the 71st Precinct, were not injured.

Marcos Gonzalez, 40, who lives near the intersection where the shooting occurred, said he heard "a lot of quick shots."

"They sounded pretty close to me, so I rolled off from bed, got down on the floor and waited for the shots to stop," he said. "All I knew was to get down, 'cause it was so loud I was scared it was coming somewhere close to me."  

Gonzalez said he has lived in Prospect-Lefferts Gardens for 15 years and this is a "fluke incident" for the neighborhood.

Garrett Russo, manager of the Taste of Brooklyn Café at 429 Rogers Ave., said in a telephone interview shortly before 9:20 a.m. that he had just arrived at work and was preparing for the restaurant’s 11 a.m. opening. He said the scene was “locked down.”

“There are a lot of police and there are people standing around,” Russo said. “The whole corner [Rogers Avenue and Lefferts Avenue] is taped off.”