The ambush, which Police Commissioner Dermot Shea said "should outrage all New Yorkers," happened just before 8:30 pm in the South Bronx.
The officer at the wheel of the van was grazed in the chin and neck, but he avoided serious injury, Shea said. He was expected to released from the hospital Sunday.
"He is lucky to be alive," Shea said. "He is expected to make a full recovery and it is a miracle."
Shea recalled other unprovoked assaults on police officers sitting in their patrol vehicles.
In 2017, a gunman killed Officer Miosotis Familia as she sat in her patrol vehicle in the Bronx. In 2014, two officers, Rafael Ramos and Wenjian Liu, were shot dead in their patrol car in Brooklyn by a man upset about recent police killings of unarmed black men. Shea said Ramos and Liu's deaths were "not something that engenders anything but the worst memories."
Mayor Bill de Blasio, a Democrat, condemned the latest attack at a news briefing outside the Bronx hospital where the wounded officer was being treated.
"There's too much hatred in general, there's too much hatred being directed at our officers, and it has to end," the mayor said. "We have to move forward in a situation like this and find a way to create a peaceful society, not one where those who protect us are in danger in this way."
The two uniformed officers, partners for eight years and friends since middle school, were sitting in their van with emergency lights activated when a man approached them and engaged them in conversation, Shea said.
The man asked the officers for directions, then pulled out a gun "without provocation," the commissioner said. The man fired multiple shots, striking the officer behind the wheel. Shea said the officer's carotid artery narrowly avoided injury.
Neither officer returned fire. The officer's partner drove him to a hospital nearby. Shea called both officers "heroic" for their composure and said their long association made for "an amazing story."
Officers had a basic description of the gunman, who fled after the shooting, but his identity was unknown. Security video that appeared to capture the shooting shows the van driving quickly away as a man appeared to point something at the fleeing vehicle.
The officers had been stationed in the neighborhood because of recent drug activity and violence, Shea said.
The president of the police union, Pat Lynch, said the department will use "all its resources" to bring the shooter to justice.