The case will now go back to the High Court
The UK's enforceable retirement age of 65 is not in breach of EU legislation, according to a ruling by the European Court of Justice (ECJ).
The case was brought by Age Concern, which wanted to know whether it was legal for UK employers to force workers to retire at the age of 65.
But the ECJ said the practice was legal if it had a legitimate aim related to employment and social policy.
It said the High Court in London had to decide if the age limit was justified.
As the law stands, a British employer can dismiss a member of staff without redundancy payments on that person's 65th birthday.
Age Concern maintained that this was in breach of the EU's Equal Treatment at Work Directive and said one in eight MPs would be out of a job immediately if the rule applied to them.
The Conservatives and Liberal Democrats had supported the case, which was also backed by Help the Aged.
The government points out that existing employment equality regulations do give employees the right to formally request to carry on working beyond 65.
It says the existing law will be re-examined, and could be relaxed further, in 2011.
The European judges said that the enforceable retirement age could remain if it had a "legitimate aim" linked to social or employment policy.
The High Court, which sent the case to the ECJ for clarification on the law, will now have to decide whether the aims of the government's retirement age of 65 were "legitimate".
Campaigners said they were disappointed with the result, but urged the government to change its policy anyway.
"We are disappointed with the ECJ's judgment which sends the message that ageism is less important than other forms of discrimination, but we will continue our fight to ensure that older British workers are judged on their skills and abilities rather than their age," said Gordon Lishman, director general of Age Concern.
"The government continues to consign tens of thousands of willing and able older workers to the scrapheap. It is time for ministers to find the courage of their convictions and abolish the default retirement age without further delay."
And Paul Cann, director of policy for Help the Aged, said that, given the difficult economic climate, the case had become even more important for pensioners who wanted to continue working so they could be more comfortable.
"Mandatory retirement ages are unfair and the government should act to abolish them as soon as possible," he said.
"Challenging financial circumstances mean it is even more important for older workers to be able to choose to work longer if they want to. Ageism in all its forms must be eradicated from our society once and for all."
The latest verdict, in what was seen as a test case, still leaves about 260 legal actions pending in tribunals.
Thousands more pensioners who were forced to retire against their will have compensation claims waiting if the High Court's final ruling decides the compulsory retirement age is not justified.