Labour's ruling body has won its bid to block 130,000 new party members from voting in the leadership election.
A Court of Appeal ruled that the party was within its rights to block members who joined after 12 January from voting in the leadership contest.
It overturned a test case ruling on Monday in favour of five members who said they were unlawfully "frozen out" from voting in the contest.
Announcing the decision, Lord Justice Beatson, sitting with Lady Justice Macur and Lord Justice Sales, said: "On the correct interpretation of the party rules, the National Executive Committee has the power to set the criteria for members to be eligible to vote in the leadership election in the way that it did."
The decision could be seen as a boost for Owen Smith, who is taking on Jeremy Corbyn in the contest.
There have been suggestions the majority of the recruits barred from voting would have backed Mr Corbyn.
When asked if he was celebrating the court ruling, Mr Smith told Sky News: "No, not at all. I am here in Corby in the east of England, talking to party members and I will carry on doing what I am doing which is getting out there, making my case."
He added that the NEC is the "correct body" to set the rules for the party and added: "I don't think by and large we should be in the courts debating these things."
A spokesperson for Mr Corbyn said the decision was wrong, "both legally and democratically".
They said: "Crucial to the outcome today was the introduction of a new argument by the Labour Party HQ's lawyers, who invoked an obscure clause in the Labour Party rules (Chapter 4, Clause II, 1.A), which could be read as giving the NEC the right to ignore all of the rules laid out for leadership elections.
"In other words, this is a 'make it up as you go along' rule. We do not think that making it up as you go along is a reasonable way to conduct democracy in our party.
"Serious questions must be raised, however, over why and how the NEC Procedures Committee brought this appeal.
"In doing so, it effectively risked new members' money on an attempt to disenfranchise them."
The judges had been urged to overturn a test case ruling on Monday in favour of five members who said they were unlawfully "frozen out" of the contest between Mr Corbyn and Mr Smith.
Iain McNicol, the party's general secretary, led the appeal against Mr Justice Hickinbottom's decision that swept away a ban on recruits who joined after 12 January being able to cast a ballot.
The High Court declared on Monday that refusing these members the vote would be an unlawful breach of the party's contract with members as set out in the rule book.
Lawyers for the five - Christine Evangelou, the Rev Edward Leir, Hannah Fordham, Chris Granger and "FM", a teenage member - had argued that the NEC had no power to retrospectively freeze a full member's ability to vote.
An application by the five for permission to appeal to the Supreme Court was rejected - but they can still apply directly to the highest court in the UK if they want to attempt to take their case further.
The NEC said in a statement that it "welcomed" the decision, adding: "It is crucial to the Labour Party that our governing body has the authority to debate, decide and implement the procedures, timetable and voting eligibility for our internal elections and selections. "The original Court decision had wide-ranging implications for the party and the authority of our governing body. It was the correct decision to seek clarification on this fundamental principle in the Court of Appeal."