An NYPD officer was shot in the foot by an alleged gunman who attempted to flee police custody on Wednesday morning, officials said, prompting a shootout on the streets of Brooklyn.

The altercation began shortly before 9 a.m., when police responded to a call of a man destroying a wall inside an apartment on Gates Avenue near the border of Clinton Hill and Bedford-Stuyvesant.

Officers were in the process of arresting Raheem Joye, 41, for alleged criminal mischief when he fired a single shot from his 9 mm handgun, striking an officer in the foot, according to NYPD Chief of Detectives James Essig, who briefed reporters hours after the incident Wednesday.

Joye then fled, dashing across Bedford Avenue with several officers in pursuit, police said.

“As he’s running down the street, he has the gun in his right hand, the officers confront him and shots are exchanged,” Essig said.

Joye fired two additional shots, while officers fired six times, striking Joye in the thigh, police said. He was detained shortly after and hospitalized in stable condition.

At the same press conference, Mayor Eric Adams praised the responding officers.

“We have a dangerous person off our street, we have an illegal gun off our street,” he said.

The officer – who has not been identified – was released from the hospital Wednesday afternoon, police said.

Investigators said Joye had several previous arrests in Georgia, along with a warrant out for his arrest in Troy, New York for illegal gun possession.

This story has been updated with additional information.