A passenger jumped from a car and opened fire in the middle of a D.C. street Wednesday morning after an off-duty police officer spotted a Mercedes being driven erratically and began following it, police said.

The shots were fired shortly before 10 a.m. on a residential street in the Eckington neighborhood, and then the gunman hopped back into the car, which on-duty officers spotted and pursued until it crashed, according to D.C. police.

The off-duty officer, in plainclothes, and his personal vehicle were not hit by the gunfire, police said. Police said it was unclear whether the gunman knew that he was shooting at an officer.

Interim D.C. police chief Peter Newsham decried the “mentality where people feel they can discharge firearms in our city.”

“It has to stop,” he said.

The incident began about 9:50 a.m. at Third and U streets NE and ended about a mile away in the crash, a sprawling path marked by three crime scenes. Police said they recovered the vehicle and a handgun and arrested two men.

Newsham said that after the off-duty officer saw the Mercedes moving erratically, he called for help and began to pursue the vehicle. Newsham said the vehicle stopped and a passenger got out and “fired multiple shots” at the off-duty officer.

The gunman jumped back in the Mercedes, and the driver sped off, the chief said. Then on-duty officers spotted the car and began to pursue it with the help of a police helicopter.

The Mercedes stopped in the unit block of W Street NW in the Bloomingdale neighborhood. There, Newsham said, an officer fired his gun. The chief said he did not yet know why the officer took the shot. No one was injured.

Newsham also said police investigators were checking to determine whether the officers involved had activated their body cameras.

Police arrested the passenger and seized a weapon, Newsham said. The driver sped off and the pursuit continued to the 1900 block of Fifth Street NW, near the Howard Theatre in the Shaw neighborhood, where Newsham said the Mercedes plowed into several parked cars. The driver was caught after a foot chase, the chief said.

Police said Edward Darnell Bolling Jr., 29, of Sacramento was charged with assault with a dangerous weapon, possession with intent to distribute, fleeing and eluding, and leaving after colliding. The identity of the other man had not been released as of Wednesday night. Newsham said detectives were trying to determine whether the Mercedes was stolen.

Correction: This article has been updated to correct an earlier version that stated a D.C. police officer fired on a passenger of a car during a pursuit. The officer discharged his weapon, but not at a passenger.