A retired NYPD officer arrested Tuesday night after getting into a scuffle with Secret Service agents outside Trump Tower was released after a brief hearing in federal court in Manhattan on Wednesday.

Anthony Shark, 54, was identified in court as a security guard at the Harry Winston jewelry store on Fifth Avenue, near the Trump Tower block where the Secret Service controls access to protect Republican candidate Donald Trump.

According to a complaint, around 10 p.m. — just before Trump’s motorcade arrived — agents closed off East 56th Street between Madison and Fifth to all vehicle and pedestrian traffic.

Shark approached a checkpoint, refused instructions to stop and leave, and attempted to push through a “human wall” formed by the agents, according to the complaint. He then flailed his arms, clenched his fists and grabbed at agents when they restrained him, the complaint said.

After Shark was restrained, the agents discovered a gun in a holster, but the Secret Service said he had a permit and expressed no hostile intent toward “any Secret Service protectees” — a reference to Trump.

In court, prosecutors agreed to Shark’s release without bail, and said he could keep his firearm, which he needs for his job, on condition that he stay out of Trump Tower.

They also wanted him to stay off nearby streets, but Shark’s defense lawyer said it wasn’t necessary. “Can I trust you to stay away from the Secret Service?” Magistrate Barbara Moses asked Shark.

advertisement | advertise on newsday

“Yes,” he said, and she waived the condition.

Shark declined to comment and shielded his face as he left court.