The suspect, who did not fire shots at the school in the town of Esslingen near Stuttgart, had entered the building briefly, left of his own accord and fled on a motorcycle, police said on Twitter.
They described the suspect as "male, aged 17-19, 170-180cm tall, bearded, darker skin, (wearing) a blue t-shirt & light shorts".
1305: Update to description of suspect: male, aged 17-19,170-180cm tall, bearded, darker skin, wears a blue t-shirt & light shorts #FES1707— Polizei Reutlingen (@PolizeiRT) July 17, 2017
Witnesses told police they had seen a firearm tucked in the teenager's waistband.
Police had earlier detained another suspect but released him after determining they had the wrong man.
They searched the secondary school but found nothing suspicious and asked students to assemble outside the building until they could be picked up by their parents, a police spokesman told DPA.