The legal ban on smoking in public places does not apply to state prisons and other Crown premises in England and Wales, the Court of Appeal has ruled.
Three judges allowed a Government appeal against a High Court ruling that the ban covered all public places and all workplaces, including those for which the Crown was responsible.
The judges unanimously agreed that the Crown was not bound by the smoking ban legislation.
Government lawyers had warned the court at a recent hearing that a "particularly vigorous" ban on smoking in state prisons could cause discipline problems and risk the safety of staff and inmates.
The appeal court decision was a defeat for sex offender Paul Black, an inmate at HMP Wymott in Lancashire, who has been serving an indeterminate sentence since 2009 and won the High Court decision in favour of the legal ban.
In reality, smoking is generally not allowed in state-run prisons, except in cells designated for smokers. The ban already applies to private prisons as they are not Crown premises.
Black complained that prison rules were being flouted and needed to be made legally enforceable under Part 1 of the 2006 Health Act, which came into force in July 2007.
His lawyers told the courts that he suffered from a range of health problems due to frequent exposure to second-hand smoke in areas of Wymott, in particular on landings, laundry rooms and healthcare waiting rooms.
Black gave evidence that staff and prisoners were guilty of illicit lighting-up in areas where it was not allowed and not enough was being done to stop them.
His health problems exacerbated by smoke include hypertension and heart disease. A number of other prisoners served statements in support of his claim.
High Court judge Mr Justice Singh ruled in March 2015 that it was "Parliament's intention" that the Health Act should apply in places for which the Crown was responsible and that intention should not be frustrated.
But on Tuesday the appeal judges - Lord Dyson, Master of the Rolls, sitting with Lord Justice McCombe and Lord Justice David Richards - disagreed and set aside the Singh decision.