Canon Jeremy Pemberton, a Church of England priest for more than 30 years, had his permission to officiate revoked after he married Laurence Cunnington in April 2014.
He was also denied a licence to officiate in the diocese of Southwell and Nottingham, which left him unable to take up a job offer at the King's Mill Hospital in Sutton-in-Ashfield.
Canon Pemberton brought an employment tribunal against the former acting Bishop of Southwell and Nottingham, the Rt Rev Richard Inwood, but his claims of discrimination and harassment were dismissed - a decision upheld by the employment appeal tribunal in 2016.
He renewed his fight at London's Court of Appeal, where his lawyers argued that the tribunal decisions should be overturned.
But, in a written ruling on Thursday, Lord Justice Underhill and two other judges found the bishop's decision was lawful under the Equality Act.
The judge said: "I have no difficulty understanding how profoundly upsetting Canon Pemberton must find the Church of England's official stance on same-sex marriage and its impact on him.
"But it does not follow that it was reasonable for him to regard his dignity as violated, or an 'intimidating, hostile, degrading, humiliating or offensive' environment as having been created for him, by the Church applying its sincerely-held beliefs in a way expressly permitted by Schedule 9 of the (Equality) Act.
"If you belong to an institution with known, and lawful, rules, it implies no violation of dignity, and it is not cause for reasonable offence, that those rules should be applied to you - however wrong you may believe them to be.
"Not all opposition of interests is hostile or offensive."
Stay up to date with the latest news stories from a Christian perspective. Sign up to our daily newsletter and receive more stories like this straight to your inbox every morning.