The teenager, who was not immediately named, allegedly fired at least one shot at his school, then fired several more times after he was tracked down to a sports field in the Bavarian town of Memmingen near Munich.
Following a tense standoff with police, he surrendered to officers, a police spokesman said. No one was injured and he was eventually taken in for psychological evaluation.
Police said the shots fired at the sports field were not deliberately aimed at them, and at one point the boy reportedly threatened to take his own life.
Media reports also said he may have been involved in a dispute with a fellow pupil or a former girlfriend. An online news channel, n-tv, said the weapons belonged to the boy's father.
The boy had earlier charged into his school with two weapons, firing at least one shot before fleeing. No one was injured in this incident either, police said.
After the alarm was raised, all 280 pupils were told via loudspeaker to remain in their classrooms while teachers closed off the rooms.
Police special units rushed to the school and, after a search, pupils were led outside, the spokesman said. All pupils were returned to their parents safe and sound.
On March 11, 2009, a masked 17-year-old named Tim Kretschmer burst into his former school and picked off nine fellow pupils and three teachers, mostly with expert execution-style shots to the head.
A further three people lost their lives in a dramatic chase and shootout with police before Kretschmer, cornered, turned the gun on himself.
It was the worst school shooting in Germany since April 2002, when 19-year-old Robert Steinhaeuser, a disgruntled student from Erfurt in eastern Germany who had been expelled, killed 16 people and then himself.
After the massacre in Winnenden, schools put into place special drills toprevent such incidents occurring again.