"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.
Get the latest election news, live updates and election schedule for Lok Sabha Elections 2019 on ndtv.com/elections. Like us on Facebook or follow us on Twitter and Instagram for updates from each of the 543 parliamentary seats for the 2019 Indian general elections.