Authorities said the suspect, who was armed with an assault-style rifle and appeared to have acted alone, drove to Buffalo from his home in a New York county "hours away" to target the store in an attack he broadcast on the internet.
Eleven of the 13 people struck by gunfire were Black, officials said.
The suspect, who was not immediately named by police, was heavily armed and dressed in tactical gear, including body armour, police said.
When confronted by officers in a vestibule of the store, the suspect held a gun to his own neck but they talked him into dropping the weapon and surrendering, Buffalo police commissioner Joseph Gramaglia told a news briefing.
Gramaglia said the gunman shot and killed three people in the parking lot of the Tops Friendly Market before exchanging fire with a former police officer working as a security guard for the store, but the suspect was protected by his body armour.
The guard was one of the 10 people shot to death in the incident, the nine others all being customers. Three other employees of the store, part of a regional chain, were wounded but are expected to survive, authorities said.
Stephen Belongia, the FBI special agent in charge of the bureau's Buffalo field office, said the attack would be investigated both as a hate crime and as an act of "racially motivated violent extremism" under federal law.
"This person was pure evil," Erie County sheriff John Garcia said, his voice quaking with emotion. "It was a straight-up racially motivated hate crime from somebody outside of our community."
Shonnell Harris, a manager at Tops supermarket, told the Buffalo News she thought she heard as many as 70 gunshots and that she fell several times as she ran through the store to a rear exit.
"He looked like he was in the Army," she told the newspaper, describing the camouflage-clad assailant.
Retired firefighter Katherine Crofton, who lives nearby, said she witnessed the start of the bloodshed from her porch.
"I saw him shoot this woman," Crofton told the paper. "She was just going into the store. And then he shot another woman. She was putting groceries into her car. I got down because I did not know if he was going to shoot me."
The suspect was expected to make his first court appearance to face murder charges by day's end, officials said.
"This is a day of great pain for our community," Buffalo Mayor Bryon Brown told reporters. "Many of us have been in and out of this supermarket many times. ... We cannot let this hateful person divide our community or our country."
Brown said he had received calls from the White House and New York's attorney general, Letitia James.
US Representative Jerry Nadler, a New York Democrat and chairman of the House Judiciary Committee, said the attack appeared to be the work of a violent white supremacist.
"We must pass the Domestic Terrorism Prevention Act, without delay," he wrote on Twitter.
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.