Two undercover detectives in Camden, N.J., were ambushed on Tuesday night by a gunman who walked up to their unmarked car at a red light and fired as many as 25 rounds at them, the police said.

The detectives, who were expected to survive, were working in plain clothes when the shooting began around 8:30 p.m. in Camden, across the Delaware River from Philadelphia, the police said.

“They were essentially ambushed,” Chief Scott Thomson of the Camden County Police Department said at a news conference.

The detectives were taken to Cooper University Hospital, where they were being treated late Tuesday. Chief Thomson did not describe the detectives’ injuries.