Police in Miami said five suspects were taken into custody in connection with a shooting that wounded an officer on Wednesday.

Miami-Dade Police Director Alfredo Ramirez told WTVJ-TV that the officer was conducting a narcotics investigation around 4 p.m. near the 500 block of Northwest 42nd Street and was "ambushed" from behind while approaching another suspect he intended to arrest.

The shot grazed the officer, who was treated and released from Jackson Memorial Hospital, Ramirez said.

A 32-year-old man was accused of being the gunman and was expected to be charged with attempted murder of a law enforcement officer with a firearm. A 30-year-old was charged with solicitation to commit first-degree murder, police said.

JAKE PAUL RUNS AWAY FROM ALTERCATION WITH FLOYD MAYWEATHER AFTER HEAT GAME

Florida Fox News graphic

Miami police arrested five people after an officer was wounded in a shooting while conducting a narcotics investigation. (Fox News)

CLICK HERE TO GET THE FOX NEWS APP

Three others were taken into custody and accused of harboring the alleged gunman after the shooting, Ramirez said.

Ramirez did not identify the officer who was hurt, but said he was a department veteran of about 18 years including undercover work.

"I did that job myself, you have to blend into the environment and you’re following criminal element and there are risks with that but that’s the only way that you can stop violent criminal activity," Ramirez said.