Robert Kelly of Middletown, 70 miles northwest of New York City, received the sentence after his lawyers had an opportunity to ask for a shorter sentence.
Prosecutors recommended two to six years in October when Kelly pleaded guilty to one count of first-degree rape in a plea bargain.
The boy admitted in court to forcing himself on the unidentified girl in 2012, when she was 9.
Kelly and the girl knew each other, the Middletown Times Herald-Record reported.
Orange County Judge Nicholas De Rosa gave the defense in October an opportunity to provide "compelling information" in favor of a shorter sentence, the newspaper said.
De Rosa ruled Friday in favor with the prosecutors' plea deal. He also agreed with the prosecution request not to give the case youthful offender treatment.
A youthful offender designation would have sealed the record.
Members of Congress to keep receiving porn magazine
Rosie O'Donnell unveils nearly 50-pound weight loss