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.

READ MORE: 'Today, I Can Rejoice': New Yorkers Hit The Streets After Jury Finds Derek Chauvin Guilty In George Floyd's Death

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.

READ MORE: Activists Celebrate Conviction Of Derek Chauvin In George Floyd's Death, But Say Fight Is Not Over: 'Tomorrow, We Still Have To Dismantle Systemic Oppression'

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.

MORE NEWS: Police: Gabriel Dewitt Wilson In Custody After Deadly Shooting At West Hempstead Stop & Shop

MORE FROM CBS NEW YORK