The boy, whose identity is being withheld, is charged as a juvenile with criminal sex act. He was picked up by detectives Wednesday after they received a tip.
Police distributed surveillance video of the suspect loitering in the McDonald's for nearly two hours before the attack, which happened around 8:30 p.m. Tuesday inside the play area at the restaurant at 181-25 Hillside Avenue in Jamaica. The tip came in hours after the video was released.
Police had originally described the suspect as being in his late teens or his 20s.
Detectives are still investigating whether the teen is linked to a groping in the same McDonald's in March and a possible luring in April.
They did not immediately link the Tuesday assault to the others.
The 4-year-old victim in Tuesday's attack was with her mother and younger brother, playing in the Play Palace.
Police say the suspect hid inside a tubular play structure in the play area, lying on his back where the mother could not see him. After the girl climbed up the staircase leading to the slide, investigators say the boy assualted her inside the tube.
The girl slid down the slide to get away, then ran to her mother and told her what happened.
Authorities say the mother ran after the suspect and grabbed him by the shirt, but he wiggled free and ran across Hillside Avenue to get away.
The girl was taken to Queens Hospital for treatment.
In family court on Thursday, prosecutors said the suspect has also been suspended from junior high school for masturbating in school. They also said that he has an 8-year-old sister at home.
The judge will keep him in custody at the juvenile justice center.