An 18-year-old man has been arrested at the scene in the city of Buffalo. He has not been named by police.
The suspect entered the busy supermarket on Saturday before opening fire while using a camera to live-stream the attack online, police said.
The FBI is investigating the shooting - which left three other people injured - as a racially-motivated hate crime.
At a news conference, police said the suspect was carrying heavy weaponry while wearing body armour and a tactical helmet.
"This is the worst nightmare that any community can face and we are hurting, we are seething right now," Buffalo Mayor Byron Brown said.
He added that the suspect was not from the city and is believed to have driven for several hours to reach the predominantly black area of Buffalo.
"We are investigating this incident as both a hate crime and a case of racially motivated violent extremism," Stephen Belongia, the special agent in charge of the FBI's Buffalo office, told the news conference,
Speaking to CBS earlier on Saturday, a police source said the detained suspect allegedly shouted racial slurs during the attack.
US President Joe Biden has been briefed on the shooting. "The president and the first lady are praying for those who have been lost and for their loved ones," a White House statement said.