The boy was taken to the hospital by a passing ambulance that was already carrying another patient.

The police said the man and the child were not related, and neither was the intended target. On Friday afternoon, the police arrested Angel Eaddy, 27, of Crown Heights, Brooklyn, and charged him with the shooting. A motive was not immediately clear. Mr. Eaddy had a prior arrest on an assault charge in 2016.

Mr. Eaddy lived in a two-story rowhouse on Park Place, only three blocks from the shooting, according to the police. A neighbor, Eric Thompson, 41, said Mr. Eaddy appeared to be “a good guy” who was friendly with his neighbors and had a job with FedEx.

Geo Primus, who works at the Food Universe grocery store at 243 Schenectady Avenue, said the store’s surveillance cameras captured the shooting.

He said the footage showed a man, wearing a white T-shirt, red shorts and basketball sneakers crossing the street and stopping in front of the supermarket. Mr. Primus said the man pulled out a gun and fired about six shots at passers-by near Lincoln Place.

“It was very reckless,” Mr. Primus said in a phone interview. “Who knows how many people could have been hurt? It was literally just bystanders.”