"On the complaint of a relative of the victim, the accused boy has been arrested," said Jewar police station SHO Rajpal Singh Tomar.
The 12-year-old girl had gone to a market for shopping on Sunday afternoon.
It is alleged that her neighbour, also a minor, forcibly took her to his home and held her captive in a stable meant for animals, a police official said.
On Monday, when the parents of the girl lodged a missing complaint, the accused set her free, he said.
An FIR has been lodged under the Protection of Children from Sexual Offences Act (POCSO) under relevant sections related to kidnapping and attempt to rape.
As the accused is a minor, he has been sent to a remand home, an official said.