Three New York City police officers were injured after being attacked with a machete near New Year’s Eve celebrations in Times Square, authorities said.

The incident happened just after 10 p.m. ET at West 52nd Street and 8th Avenue, just outside the high-security zone where revelers are checked at checkpoints, officials said in a Press conference early sunday.

The suspect approached an officer and attempted to hit him over the head with the machete, Commissioner Keechant Sewell said. He then struck two officers in the head with the blade before being shot in the shoulder and taken into custody by police, Sewell said.

Several law enforcement officials told NBC News they were investigating whether the suspect had previously posted what they called jihadi writings online and traveled to New York to attack police on New Year’s Eve.

The officers were hospitalized, one with a fractured skull and another with a severe cut, but were in stable condition, Sewell added. The suspect was also hospitalized, he said.

Mayor Eric Adams said at the news conference that he had spoken with one of the injured officers. “He understood that his role saved the lives of New Yorkers today,” Adams said.

The investigation was in its early stages, but law enforcement agencies knew of the suspect from his social media posts, authorities said, adding that he had no criminal record.

authorities in the Press conference identified the suspect only as a 19-year-old male. Four senior law enforcement officials told NBC News that the man had been identified as Trevor Bickford of Wells, Maine.

Neither the FBI nor the New York police were looking for additional suspects, authorities said.

The New York Police Department mounts a massive security operation every year during the New Year’s Eve celebrations, with thousands of officers deployed around Times Square.

Crowds are not allowed into the blocks to watch performances and the midnight ball drop without being checked at checkpoints where officers use metal detector wands to detect weapons.

Large bags and coolers are prohibited in the area, while barriers are in place to prevent vehicle attacks in the secure area.

Associated Press Y alex lo contributed.