NEW YORK — A man wielding a machete attacked three police officers at the New Year’s Eve celebration in New York City, authorities said, striking two of them in the head before an officer shot the man in the shoulder.

The attack happened a little after 10 p.m. about eight blocks from Times Square, just outside of the high-security zone where revelers are screened for weapons.

The two officers were hospitalized, one with a fractured skull and the other with a bad cut, and were expected to recover.

The 19-year-old suspect, whom police did not identify but whom local media identified as Trevor Bickford of Wells, Maine, also was expected to recover. NBC 4 in New York reported police are investigating the attack as a possible terrorist act and whether Bickford had posted jihadist writings online.

ABC News reported that Bickford took an Amtrak train to New York on Thursday. 

News Center Maine reported that FBI agents were at his family’s home on Sunday. 

Bickford is a 2022 Wells High School graduate, the news station reported, and he worked at a local country club as a groundskeeper last summer. 

The attack and sound of a gunshot briefly sent some people in the crowd running, but the incident did not impact the festivities in Times Square, which continued uninterrupted.

Mayor Eric Adams said at a news conference that he had spoken to one of the wounded officers as he was being stitched up at the hospital.

“He was in good spirits,” Adams said. “He understood that his role saved lives of New Yorkers today.”

An investigation was underway to pinpoint a motive for the attack, but authorities said they didn’t believe there was any ongoing threat to the public.

Michael Driscoll, the assistant director in charge of the FBI’s New York field office, said the agency believes the attacker acted alone.

The NYPD mounts a massive security operation every year to keep the New Year’s Eve crowd safe. Thousands of officers are sent to the area, including many new recruits.

One of the injured officers just graduated from the police academy on Friday, the mayor said.

The blocks where the biggest crowds gather to see performances and the midnight ball drop can be accessed only through checkpoints where officers use metal-detecting wands to screen for weapons. Large bags and coolers are banned. Barriers are set up to prevent vehicle attacks.

The security perimeter can only extend so far, though. The attack took place on 8th Avenue, which is often packed with thick crowds navigating around the frozen zone or trying to find one of the secure entrances.

Kristen Setera, a spokesperson for the FBI’s Boston office, declined to comment on the investigation when asked if the office had previous knowledge of Bickford, noting that the FBI doesn’t disclose most investigations until charges are filed.

“As law enforcement officials in NY stated last night, this is very much an active, ongoing investigation,” Setera said. “The FBI’s Joint Terrorism Task Force is working closely with NYPD to determine the nature of this attack and we will run every lead to ground.”