It was the Sonata that three of the youths rode on Monday morning to Sheridan Avenue and 162nd Street, where one had to answer a charge in Bronx Criminal Court, the police said.

What they did not know is that police license-plate readers had tracked the car to the spot where it was parked, Chief Monahan said. After the court appearance, the three returned to the car and were about to drive away when the officer and her partner approached, the chief said.

The wild scene unfolded along Sheridan Avenue around 11:30 a.m., as dozens of people were going in and out of the area courts, restaurants and law offices.

Nathaliz Martínez, a legal secretary at the Goodfriend Document Center across from the family court entrance, said she heard the gunshots from the second-floor office and tried to convince herself it was just a car backfiring.

“It wasn’t even afternoon yet,” she said incredulously. “Are you serious?”

A man who did not want to be identified because he was on parole said he was coming out of the Social Security office a block away when he saw the officer spin around before hearing three shots. Within minutes, police helicopters were hovering overhead and police officers swarmed the area.

Another man, Jason Rogers, 32, said he was coming out of the Bronx Criminal Court next door on East 161st Street when he heard the shots, ducked and peered around.

“I was trying to look for the shooter,” Mr. Rogers said. “It was a rush.”

Jose Sánchez, 30, had just passed through the scanners in the Family Court when he heard a female officer yelling, “Sir, this is not an exit!” Moments later, he heard gunshots.