A judge has refused to free a prisoner who wanted to register to vote in the Scottish Parliament elections.
Lord Clarke gave his ruling at the Court of Session
However Donald Birrell - who complained that his human rights had been breached - may still be able to win damages.
Birrell was let out on licence in May last year but is now back in jail after the licence was revoked last month.
Judge Lord Clarke gave his verdict at the Court of Session in Edinburgh on Friday and said the case had raised interesting and novel questions of law.
Birrell sought a judical review when his attempt to register to vote was refused because he had been imprisoned again.
He was one of three Scottish prisoners bringing legal action ahead of May's parliamentary and local government elections.
Under current laws - the 1983 Representation of the People Act - a ban on voting is imposed on all prisoners being held under a sentence.
Remand prisoners and those freed on licence are allowed to cast their vote.
The judge said he had "no hesitation" in deciding that Birrell, formerly from Glasgow, should remain in prison.
Rejecting Birrell's bid for freedom, Lord Clarke said: "I am entitled to balance the safety and protection of the public against the right of Birrell to take part in the election."
Scottish ministers, legally responsible for the decision to send Birrell back to prison, contested his action.
Their senior counsel, Paul Cullen QC, said Birrell's rights under the European Convention on Human Rights had not been breached.
Birrell's problem was the result of his own behaviour, said Mr Cullen. Birrell had also lodged a claim for £1,000 damages if he was not allowed to vote.
SNP justice spokesman Kenny MacAskill welcomed the judge's decision.
"Clearly common sense has prevailed as people who breach the law forfeit some rights and must face the consequences of their actions," he said.
"Hard pressed courts and limited court time should be for serious offenders and important issues, not spurious cases such as this."
Separate cases are being brought by the other two inmates, Derek Traynor and James Fisher.
They hope to halt the elections altogether if they are successful.
The pair are seeking a court order to ban ministers from "carrying out any act to facilitate or promote the holding of the general election for membership of the Scottish Parliament".
The moves follow a ruling in January by Court of Session judges that a blanket ban on prisoners voting was not compliant with the European Convention on Human Rights.