To the monks of Mont Saint-Odile, perched high in the Vosges mountains, it seemed like the work of the devil. During nearly two years of doubt and mystification, 1,100 ancient books disappeared from the monastery library without any trace of a break-in.

Yesterday, in a court in Saverne, Alsace, the mystery reached its conclusion when the thief, Stanislas Gosse, 33, was given a suspended sentence of 18 months for a burglary that had echoes of Umberto Eco's The Name of the Rose and a touch of Harry Potter and the Chamber of Secrets.

The judge was told of a lost map, a secret passage and a hidden entrance through a cupboard, all finally revealed by routine modern technology - CCTV cameras.

But the thief, who baffled priests and detectives between August 2000 and May 2002, said he was driven by pure passion for the priceless books, filling his little Strasbourg flat with massive volumes dating back to the XVth century. Some, with wooden covers and weighing several kilos, he had carried off on his bicycle.

Gosse, a teacher at a Strasbourg engineering school and a former naval officer, faced a rare charge of "burglary by ruse and escalade", a reference to the tortuous climb in and out of the locked library.

He had found the route after discovering a forgotten map in public archives which revealed the secret access from the monastery attic.

The map was a key exhibit in the trial. The attic, reached by a daring climb up exterior walls, led to a steep, narrow stairway and then the secret chamber. A hidden mechanism opened up the back of one of five cupboards in the library. The plans suggested that the secret route to the library, once the monastery's common room, served in medieval times to spy on the monks' conversations.

Inside the library, Gosse spent hours by candlelight picking out volumes, some of which he stored in the attic.

In an atmosphere of general suspicion among the nuns and monks of Mont Saint-Odile, the librarian, Alain Donius, called the police to report that entire shelves had been cleared. But though the locks were changed and the library door reinforced with steel, books continued to disappear at a steady rate during the police inquiry.

Gosse was so confident he left a rose on the main entrance door to tease Father Donius after a particularly successful visit. Gosse told the court: "I'm afraid my burning passion overrode my conscience. It may appear selfish, but I felt the books had been abandoned. They were covered with dust and pigeon droppings and I felt no one consulted them any more. There was also the thrill of adventure - I was very scared of being found out."

The mystery was finally solved when police installed a hidden video camera while the monks and nuns attended their Pentecost services. As night fell, the police watched Gosse fill three suitcases with books. They arrested him while he was still carrying the rope he needed to climb down the outer walls.

In his flat, they discovered he had, on some books, carefully covered up the monastery's bookplates with his own personal labels.

Gosse's counsel, Cathy Petit, said her client had taken great care of the books and even restored some of them. She requested he got a community service sentence to help the monks catalogue their treasures, but the judge added fines and damages of 17,000 euros (£11,835) to the suspended prison term.

The public prosecutor, Jean Dissler, said the archbishop of Strasbourg and Father Donius had forgiven Gosse and they wanted him to continue as a teacher, a request granted by the court. They have also told him he can come back to the library - but only through the front door.