A gay man has won a battle at the UK's highest court to secure his husband the same pension rights a wife would enjoy.

Ex-cavalry officer John Walker, 66, was present to hear five justices at the Supreme Court in London unanimously allow his appeal against an earlier ruling against him.

Mr Walker suffered a defeat at the Court of Appeal in 2015, when judges ruled that his claim failed because it applied to a period before gay civil partnerships were recognised by the law.

But on Wednesday, the Supreme Court justices ruled that Mr Walker's husband is entitled on his death to a spouse's pension, provided they stay married.

Mr Walker launched legal action because he wanted to ensure that, should he die first, his husband, who is in his fifties, will be adequately provided for.

Human rights organisation Liberty said before the ruling that a successful outcome could "dramatically change the lives of thousands of same-sex couples".

Liberty said Mr Walker's case had challenged "an exemption in the Equality Act that lets employers exclude same-sex partners from spousal benefits paid into a pension fund before December 2005, when civil partnerships became legal".

In their ruling the panel of Supreme Court justices, headed by the court's deputy president Lady Hale, made a declaration that the exemption under the 2010 Act was "incompatible with EU law and must be disapplied".

The decision means Mr Walker's husband will be entitled to a spouse's pension of around £45,000 a year, rather than about £1,000 which he would have received.

During the Supreme Court hearing in March, a QC for the Work and Pensions Secretary pointed out that the costs involved in "requiring all pension schemes to equalise entitlements retrospectively" would be £100 million for private sector schemes and a further £20 million for public sector schemes.

Mr Walker retired from chemicals group Innospec Ltd in 2003 after working for the company for more than 20 years.

He had made the same contributions to the pension scheme as his heterosexual colleagues.

He and his husband, a former computer executive who prefers not to be named, have been together since 1993.

The Civil Partnership Act 2004 came into force on December 5 2005.

Mr Walker and his partner entered into a civil partnership in January 2006, which was later converted into a marriage.