A 21-year-old homeless man was charged on Tuesday with the attempted rape an 8-year-old girl last month, police said.

The girl was walking into her University Heights building in the Bronx at about 5:30 p.m. on Oct. 24 when she was ambushed from behind. Justin Ramirez allegedly put his arms around her mouth and put his hand down the front of her pants.

The girl started screaming and Ramirez ran, police said.

Ramirez was charged with several offenses, including multiple counts of sex abuse and endangering the welfare of a child.

He was awaiting arraignment Tuesday and could not be reached for comment.