The ban on smoking in public places does not apply to state prisons, the Court of Appeal has ruled.
Judges allowed a government appeal against a High Court ruling that the 2007 ban covered all public places and workplaces in England and Wales.
The government says it means it can carry on with its plans to roll out a ban gradually "in a safe and secure way" rather than rushing it through.
An inmate who wanted quicker implementation had brought the case.
He and some other prisoners and staff argue state prisons should never have been exempted from the 2007 ban on smoking in public places.
Smoking has, until recently, been allowed in cells and exercise yards at all 136 state-run prisons in England and Wales – the ban already applies to private prisons as they are not Crown premises.
Welsh prisons began to go completely smoke-free in January and the government says all of those in England will eventually follow suit to reduce health risks to staff and inmates.
By Danny Shaw, BBC home affairs correspondent
At the Whitehall headquarters of the Prison Service they will be lighting up in relief.
The Court of Appeal ruling means, firstly, the government can continue its steady-as-she-goes approach to introducing smoke-free public sector jails; and, second, prison officials won't be prosecuted or fined if they fail to enforce the current no-smoking ban in communal areas.
That was why Paul Black brought the case: he wanted the rules restricting smoking to cells properly enforced, as they are in pubs, for example, where local authorities can intervene.
However, the judgement does not exempt the Prison Service from being sued by inmates or prison officers for the effects of passive smoking.
A report last year provided further evidence of the risks – which is why a phased introduction of a full no-smoking ban is already under way.
Paul Black, an inmate at HMP Wymott in Lancashire, complained that prison smoking rules were being flouted and should be made legally enforceable under Part 1 of the 2006 Health Act, which came into force in July 2007.
His lawyers told the hearings he suffered from a range of health problems due to frequent exposure to second-hand smoke, in particular on prison landings, in laundry rooms and in healthcare waiting rooms.
Black's health problems included hypertension and heart disease, the court was told, and other prisoners provided statements in support of his claim.
Sean Humber, head of human rights at law firm Leigh Day, which represented Black, said the ruling seemed "absurd" to their client and they would discuss an appeal to the Supreme Court.
Government lawyers had warned that a "particularly vigorous" ban could cause discipline problems and risk the safety of staff and inmates.
That warning was echoed by the Prison Governors Association, which is in favour of a ban, but has raised concerns about it potentially leading to instability in jails, given about 80% of inmates currently smoke.
A Prison Service spokesman said: "The result of this appeal means we are able to roll out smoke free prisons in a safe and secure way.
"Our careful approach will ensure staff and prisoners are no longer exposed to second-hand smoke, while not compromising the safety and security of our prisons."
In Scotland, prisoners are allowed to smoke in their cells and in some open-air areas. Prison staff are not allowed to smoke anywhere.
A Scottish Prison Service spokesman said they were developing plans to deliver smoke-free prisons in Scotland, but no timeframe for this was available.
The Northern Ireland Department of Justice said it had no plans to change the current rules, under which smoking is permitted in prison cells and certain open spaces.