The court ruled that Mr Shayler - arrested in Paris in August after leaking information to the press on MI5 bungles - should not be extradited to Britain to face charges under the Official Secrets Act.
Three hours after the ruling, the former British security services agent left the Sante prison, wearing a light blue-and-white striped Middlesbrough second strip football shirt. He held up a clenched fist, and shouted "Justice", adding: "This is a great day for justice and a sad and embarrassing one for MI5 and the British Government."
The Government cannot appeal. As long as he stays in France, Mr Shayler is a free man.
The stunning ruling by the Chambre d'Accusation of the Paris appeal court will reinforce agitation in Britain for reform of the catch-all Official Secrets Act. It will also go down as a landmark judgment in French, and European, constitutional law.
It means that any other British security official can breach the secrets act with impunity, as long as he or she travels to France first. In these circumstances, it might not be possible for the Act to survive in its present form.
When the decision was announced, Mr Shayler's girlfriend, Annie Machon - also a former MI5 officer - and his two brothers, Phil and Jeremy, gave a cheer of delight and relief and hugged each other. Mr Shayler beamed at them and drummed his hands on the side of the dock.
Afterwards, Ms Machon said: "It's over. It's an indescribable relief. We've had three and a half months of anxiety and stress but the French judicial system has agreed that David did nothing wrong. He just wanted to tell the truth."
Later, at the prison gates, Mr Shayler said: "I'm glad to be out of prison but I shouldn't have had to spend four months there for criticising MI5." His lawyers refused to comment on his immediate plans.
For Jeremy Shayler the result was a great relief. "We are a very close family. We had no idea how the judgment would go but we believed all the good legal arguments were on our side," he said. "It's a terrific feeling that the French court has agreed with us."
The Government indicated last night that it had no immediate plans to drop its prosecution of Mr Shayler. Injunctions restricting the publication of his allegations also remain in place.
Government lawyers will also be keeping in touch with French prosecutors, who could decide to appeal against the decision.Reuse content