It happened in the Far Rockaway section of Queens. The boy had walked several blocks from summer school at P.S. 43 on Beach 29th Street when the shooting happened.
He was taken to Jamaica Medical Center in stable condition.
Other summer school students who were being dismissed heard the shots fired, police said.
All of those students went back into the school, which was put on lockdown. No students at the school at the time of the incident were injured. They were allowed to go home a short time later.
Police have not identified a suspect or a motive in the shooting.