Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Eight people were killed and about a dozen more were injured Tuesday when a motorist in a rented pickup truck deliberately drove down a bike path in lower Manhattan and mowed down several people before crashing into a school bus. Officials said it was a terrorist attack — the deadliest in New York City since Sept. 11, 2001.

The man hopped out of the truck and shouted "Allahu Akbar," or "God is great," before firing a BB or pellet gun, four senior law enforcement sources told NBC News. A police officer on patrol in the area returned fire, hitting the suspect in the abdomen and ending the Halloween horror less than a mile from the World Trade Center.

Sayfullo Habibullaevic Saipov. St. Charles, Missouri, Corrections Department

Law enforcement sources said the man left a note in the truck claiming that he committed the attack for the Islamic State terrorist group, although it was not known whether he was imitating other IS-inspired road attacks in Europe or was under the group's control.

"This was an act of terror and a particularly cowardly act of terror," Mayor Bill de Blasio said at a briefing. "We know this action was intended to test our spirit."

The suspect was identified as a 29-year-old Uzbek immigrant named Sayfullo Habibullaevic Saipov, who entered the United States in 2010, law enforcement officials said.

While police rushed the wounded suspect to Bellevue Hospital, six of the victims — all men — were pronounced dead at the scene, and two more died later, Police Commissioner James O'Neill said.

"Today, there was a loss of innocent life in lower Manhattan," O'Neill said. "This is a tragedy of the greatest magnitude."

O'Neill would not comment on whether the suspect lived in New York City or was a "radicalized American." Multiple law enforcement sources told NBC News that the suspect rented his truck from a Passaic, N.J., Home Depot and that his minivan was still parked there Tuesday evening.

Records revealed that Saipov had lived for a time in Paterson, New Jersey. The weapons investigators recovered turned out to be a pellet gun and a paintball gun.

NYPD Officer Ryan Nash apprehended Saipov, according to a tweet from Councilman Joe Borelli.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"I want to commend the response of our NYPD officer that was on post near the location who stopped the carnage moments after it began," O'Neill said.

New York Gov. Andrew Cuomo said the attack appeared to be the work of a "lone wolf."

"There's no evidence to suggest a wider plot," he said.

The FBI Joint Terrorism Task Force joined the investigation.

Photos: Terrorist Truck Attack Shocks New York City

Argentina's foreign affairs minister said five of the victims were Argentine, and the group had been celebrating the 30th anniversary of a school graduation. The official identified them in a statement as Hernán Mendoza, Diego Angelini, Alejandro Pagnucco, Ariel Erlij and Hernán Ferruch. Belgium's foreign affairs ministry said one of the victims was a national of that country. A woman from Germany was injured in the attack, a spokesperson for the German Foreign Ministry said.

Kobiljon Matkarov, a friend of the suspect who said he met Saipov five years ago, when they both lived in Florida, told NBC News that "he is no terrorist."

"He was a very happy guy," said Matkarov, who added that Saipov was married with kids and worked as a truck driver. "He liked the U.S."

The attack began unfolding at 3:05 p.m. when the southbound truck veered onto a bike path on West Street near Houston Street.

"He entered the bike path at Houston Street and exited the bike path when he collided with the bus at Chambers Street," O'Neill said.

Two adults and two children were in the bus, the commissioner said.

"You could see cyclists and pedestrians badly injured," said MSNBC correspondent and producer Louis Burgdorf, who was outside a building where Canal Street meets the West Side Highway, which is north of Chambers and the highway.

A witness, Tawhid Kabir Xisan, 20, said he saw a man running in the street carrying what appeared to be two guns near Chambers Street.

Related: NYC Truck Attack Brings Deadly Terrorist Trend to the U.S.

"He was just running around in the middle of the street," said Xisan, a student at Borough of Manhattan Community College nearby. "I heard five to six gunshots, and then when the gunshots were happening, I didn't see what happened on the road because I was scared."

When he looked up again, Xisan said, "I saw the guy that had the two guns on the ground. Three or four officers were holding him down."

Initially, the incident was reported as a shooting near Chambers Street and the West Side Highway, which is near Public School 89.

Investigators inspect the truck used in the attack. Don Emmert / AFP - Getty Images

Another witness told NBC New York that after smashing into the school bus a man got out of the truck "and started shooting up the place."

"All the kids were in the courtyard of P.S. 89 and started running," another witness said. He said he went to the struck school bus and saw that one side was caved in, with one girl struck above a wheel well and two other children trapped by a window.

"It was all blown out," he said.

In Washington, White House officials said President Donald Trump was receiving "ongoing" briefings about the attack in his hometown.

"Our thoughts and prayers are with the victims of today's terrorist attack in New York City and their families," Trump said in a statement. "My Administration will provide its full support to the New York City Police Department, including through a joint investigation with the Federal Bureau of Investigation. We offer our thanks to the first responders who stopped the suspect and rendered immediate aid to the victims of this cowardly attack. "

As detectives continued to gather evidence and extra police were dispatched to the protect the thousands of revelers at the Halloween parade in Greenwich Village, the wrecked pickup sat surrounded by yellow police tape with its hazard lights blinking.