The attack occurred inside the Countee Cullen Library on West 136th Street Wednesday afternoon.
Authorities said the eight year old girl reported that she had been attacked by a 13 year old boy in the bathroom.
The girl went to the bathroom with the boy willingly, but when she got inside she was attacked.
She did not report the attack until she got home and told her family, police said.
Detectives from the NYPD's Special Victims Unit picked up the boy and are interviewing him. He is expected to be charged as a juvenile.
The library branch was closed on Thursday, but it is expected to reopen on Friday.