Police shot and wounded a suspect while responding to a shooting in Manhattan on Friday, cops said.

The shooter was targeting two rivals when he struck one of them in the chest at W. 125th St. and Amsterdam Ave. in West Harlem around 6:22 p.m., according to a law enforcement source.

An NYPD detective and sergeant responding to that shooting then opened fire, striking the suspect in the stomach, sources said.

A witness said he saw the cops shoot the suspect and then take him into custody.

“There were shots, lots of shots,” said the man, who declined to provide his name. “The cops pull up and get out of the car, and then he was down. He was in the middle of the street, and they handcuffed him.”

Both the wounded gunman and the shooting victim were taken to a local hospital for treatment. An NYPD spokesman could not immediately provide their conditions.

This is a developing story. Check back for updates.