While New Year’s Eve is a time of joy for many, a horrible attack occurred in New York City.

A rookie NYPD police officer on his first day on the job was attacked with a machete on New Year’s Eve just blocks Times Square — and police are probing whether the suspect is a recently radicalized Islamic extremist, according to police sources.

The officer — who graduated Friday and was assigned to a Staten Island precinct but was working the New Year’s Eve detail for the night — was stationed at West 52nd Street and 8th Avenue when the machete-wielding madman approached him and two other officers around 9:30 p.m., NYPD sources told The Post. 

The post was outside the area attendees were being screened for weapons, Police Commissioner Keechant Sewell said at a press conference early Sunday.

The rookie cop was slashed in the head, prompting another cop to shoot the suspect, The rookie cop, identified by Mayor Eric Adams as Paul, was struck on the head, prompting another cop to shoot the suspect, striking him in the shoulder, the sources said. Paul suffered a large laceration and skull fracture, Sewell said.

One of the other cops, an eight-year veteran, was also struck on the head with the weapon and suffered a laceration.

The attack was “unprovoked,” Adams said at the press conference.

The suspect, a 19-year-old later identified by law enforcement sources as Trevor Bickford, was arrested and taken to Bellevue Hospital. Senior law enforcement officials told The Post that cops are investigating whether he is a recently radicalized Islamic extremist, based on online postings. 

Both wounded officers were also taken to Bellevue Hospital and are expected to recover. Both Sewell and Adams stressed there is no “active threat” to the community. 

Police are working with the FBI Joint Terrorism Task Force to investigate the shocking attack. A motive was not immediately clear.

“No backpacks or umbrellas in Times Square. They forgot to mention machetes,” a police source told The Post.

Sewell arrived to the hospital to visit the wounded cops shortly after they were admitted. The mayor arrived around 12:30 a.m. on New Year’s Day in an SUV covered in confetti. Earlier, Hizzoner pushed the button to start the ball drop countdown as spectators bid farewell to 2022.

Meanwhile, another cop was hit by a police car when he was trying to move the barricades on 52nd and Broadway to let responding officers get to the machete-wielding man, witnesses said.

“They moved the barricades really fast. He was a police officer in front of the barricade area and he moved it for police cars to move fast — and that’s when the barricade fell and got hit by the car. He got double whammied,” witness Kim Novack told The Post.

The cop was taken to Mount Sinai West and is expected to recover, police sources said.

The area had already been a hotspot for rowdiness.

Cops had to intervene when crowds were trying to tear down the barricades just an hour before the machete man ran toward cops.

The attack was also not the only in Times Square of the night. A man was stabbed in the neck with scissors around 8:45 p.m. when a fight broke out between two men on West 42nd Street and 6th Avenue.

Hours before the festivities were set to begin, another male was stabbed “around eight times” near Seventh Avenue and West 40th Street, the NYPD said. The victim was taken to Bellevue Hospital with non-life-threatening injuries, cops said.