A Brooklyn man, who threatened his ex-girlfriend while carrying a handgun and a meat cleaver on the Stony Brook University campus last year, pleaded not guilty to weapon and other charges Wednesday, authorities said.

Joseph Bryan Lloyd, 31, was indicted and arraigned on two counts of criminal possession of a weapon and one charge of menacing, Suffolk County District Attorney Thomas Spota said in a news release.

The defendant, who is in the Suffolk County jail, was arrested in October 2014 by the Stony Brook University Police Department.

Officers had responded to a 911 report that a man had forced his way into an office in the Social and Behavioral Sciences Building.

Lloyd threatened his former girlfriend, a graduate student, with the firearm, and demanded to look at her cellphone, police said.

advertisement | advertise on newsday

He fled after checking her phone only to be spotted by police on the university’s Long Island Rail Road platform.

Police then chased him into nearby woods and arrested him, officials said.

The district attorney’s office said police found a silver .38 Smith & Wesson handgun Lloyd had thrown on the ground during the chase.

State Supreme Court Justice John Collins set bail at $25,000 cash or $100,000 bond, and issued a temporary order of protection.

The defendant is scheduled to return to court Jan. 28.