“The hostage-taking is over,” said Jean-Marc Magda, aide to the mayor of the eastern French city of Besancon. All 20 children who had been seized and their teacher were released safely, he said.

The hostage-taker was detained by police officers from the elite GIPN force, who slipped into the school as the children were being brought lunch, Education Minister Luc Chatel said.

“We brought in meals, and it was at that moment that the GIPN was able to intervene, separate the children, free them and apprehend the hostage-taker,” he said in televised comments from the scene.

French television showed a wide-eyed girl being draped in a green blanket and carried away from the school. Police and worried families had surrounded the Charles Fourier preschool in Planoise, a neighborhood of housing projects with a big immigrant population on the western edge of Besancon.

The hostage-taker’s motives were unclear. Described by officials as depressive and known to the neighborhood, the teen appeared to be gentle with his preschool hostages.

He let several of the children go join their parents outside, and he did not threaten those who remained, even allowing them to go to the bathroom, Chatel said.

Besancon Mayor Jean-Louis Fousseret said the teen had been treated for depression but had not taken his medication in recent days. The mayor did not confirm reports that the youth had requested a gun to commit suicide.

The hostage-taker initially seized a class of 20 children but released 14 throughout the morning, including one who “more or less escaped,” Fousseret said.

Five or six children and the teacher were believed to be still in the preschool when the officers entered at lunchtime, he said on i-tele television.

The masked gendarmes pointed their firearms at the school’s windows and doors as they entered, in images shown on French TV. They were in contact by telephone with the hostage-taker before the last group of children was released.

President Nicolas Sarkozy welcomed the “happy ending” to the hostage-taking. In a statement, he expressed support for the teacher taken hostage and the school personnel, and praised the “sang-froid, professionalism and determination” of the police and gendarmes who helped free the children.