NEW YORK (CBSNewYork) — Police have arrested a man they say tried to rape a teenager in Brooklyn.

It happened around 1 p.m. Sunday inside a building on Foster Avenue in Midwood.

Investigators said 31-year-old David Gonzalez first exposed himself to a 14-year-old girl in a hallway.

Police are searching for a man accused of trying to rape a teenager in Brooklyn on Nov. 22, 2020. (Credit: NYPD Crime Stoppers)

When the teenager tried to run away, Gonzalez allegedly grabbed her and knocked her to the ground.

She was able to fight him off, and he ran out of the building and rode off on a moped.

The girl was not physically injured.

Gonzalez was arrested early Wednesday morning on charges of attempted rape, forcible touching and acting in a manner injurious to a child.