The judge said Health Secretary Jeremy Hunt acted "openly and lawfully" but also ruled that he had not "imposed" a contract on junior doctors.
The decision means the Justice for Health group will have to decide whether to launch an appeal. But today the group said it had successfully established that the new junior doctors' contract had not been imposed - and need not be used by employers.
In the judgement, the High Court seemed to make no concessions to the case made by the juniors.
In a statement Justice for Health said: "It is now established, beyond doubt, that the Secretary of State for Health, Jeremy Hunt, is not imposing the disputed contract on junior doctors and that employers of junior doctors are not legally compelled to use it."
It added: "Mr Hunt’s last minute legal acrobatics have saved him from losing the case but bring no comfort to the thousands affected by his actions in the last year."
The group of five junior doctors was backed with £300,000 of crowd-funding by supporters - and could potentially raise more for an appeal.
The group went to court last week argued that Health Secretary Jeremy Hunt acted outside his powers and "irrationally" in imposing the new contract after doctors rejected it in a ballot.
Government lawyers argued Mr Hunt had not imposed the contract but recommended it to the NHS.
The judgement states: "First, the Secretary of State does not purport to exercise any statutory power that he may have to compel employers within the NHS to introduce the proposed terms and conditions. Second, he acknowledges, therefore, that in principle individual employers are free to negotiate different terms with employees.”
The judge went on: “I accept the evidence of the junior doctors that they were in genuine doubt as to whether or not there was any negotiating daylight left following the Minister’s statement and, further, construed the Statement as entailing the Secretary of State compelling introduction or implementation of the contract and thereby eradicating further negotiating options.”
In a statement Justice for Health added: "Whilst we hoped for the top result, we have met our initial goal to extract clarity from the Secretary of State and will now move on. We resolve to help the BMA to exert legal pressure in any way possible to combat the exploitation of NHS staff and annihilation of good quality patient care we have witnessed at the hands of this Health Secretary."
Last night one of the Justice for Health group, Dr Ben White, tweeted: "It has been a tough journey but tomorrow at noon the truth comes out."
But media doctor Dr Phil Hammond suggested the verdict could raise wide-ranging questions about the oversight of the NHS.
He tweeted: "Is there a controlling mind in the NHS? Is there a true line of accountability? Does the Secretary of State have power beyond empty threats?"
An invitation was issued to Mr Hunt yesterday by the British Medical Association, backed by a number of royal colleges.
The BMA says it will arrange the event as a symposium to suit the Health Secretary's diary.
Some college leaders backed the BMA last night, urging Mr Hunt to take up the invitation.
Professor Derek Bell, president of the Royal College of Physicians of Edinburgh, said: “The dispute over the junior doctors’ contract has raised many issues not only relating to trainees but to the wider workforce.
"While this will not resolve the outstanding concerns with the contract, we hope that the Secretary of State will accept this offer to debate and find solutions to the current challenges facing those working on the frontline of the NHS and how to address these in the long term."
The invitation was issued jointly by BMA chair Dr Mark Porter and the chair of the junior doctors' committee Dr Ellen McCourt.
Dr McCourt said: "Over the past year, junior doctors across the country have raised concerns about the reality of caring for patients in a health service under mounting pressures and the impact on their working lives and morale.
“Today, we are calling on the health secretary to join leading voices from across the NHS, the medical profession and patient groups, to address the issues at the heart of this debate and those aspects of patient care which we all want to improve.”
Critics accused GPs of failing to maintain accurate records of patients, allowing missing patients to bring in extra income.
But the figures may also suggest the population of England is several million greater than official figures show.
According to new figures from NHS Digital, some 57.3 million patients were registered with GPs at the end of March. It represented an increase of just 100,000 since September last year.
The Office for National Statistics believes the population of England is 54.3 million. These figures date from mid 2014 and were largely an estimated based on the 2011 census, NHS Digital said.
NHS Digital said the difference could also be because dead patients - or those who had emigrated - remained registered in practices or because registered patients, such as refugees, had not completed the 2011 census.
Efforts by some regions of the NHS to "cleanse" lists and remove people who never visit the GP have sparked controversy and raised fears that some people could be left without GPs.
The deputy chair of the British Medical Association's GP committee Dr Richard Vautrey said the figures might indicate inaccuracies in the national census.
He said: “For decades there has been debate as to whether census data or practice registration data is the most accurate. Many people who for whatever reason are reluctant to complete the census are registered with practices.
“It is also not surprising that many patients understandably take time to alter their details when they have moved home, which can commonly explain why people remain on a practice list when they have left the area. It is now also complicated by the fact that patients can now register with a GP when they live outside the practice area.
“GP practices already routinely contact patients in an effort to keep their lists up to date and it is important the public are properly informed about how to change their details."
But John O'Connell, of the Taxpayers' Alliance, said: "We rarely see a day go by without the NHS asking for more taxpayers' money or claiming that there are no more savings to be made.
"Yet a system that allows around three million people to be left on the books who may have died or moved home is one that is deeply flawed and wasteful."
Doctors' leaders condemned the numbers as "woefully inadequate."
The NHS Digital figures showed GP numbers increasing by 108 between September last year and March this year.
And the increase in numbers mostly came from the recruitment of additional registrars and locums - as the numbers of fully qualified GPs fell, the figures show.
The number of GP providers fell from 22,390 to 21,029 while the number of others GPs - such as salaried doctors - fell from 10,063 to 9,924.
While the figures may reflect the impact of retirement, they show practices unable to fill vacancies with GP registrars, in spite of an increase in the number of doctors filling training posts.
They also cast doubt on the success of efforts to entice qualified GPs back into general practice from career breaks and overseas postings.
The figures show a reduction in part-time working - meaning that the 108 extra doctors contributed to an increase of 323 in the full time equivalent number of GPs.
The figures show that more than 25% of GPs in London are over the age of 55 - the greatest proportion in England.
According to the figures, there was a small increase in the number of practice nurses - of 86 - during the period but a larger increase in non-clinical staff working in practices. These increased by 625 to 93,926.
The figures also confirm a steep fall in the number of independent practices - a reduction of 61 in six months - to 7,613. Some 9.3% of practices are run by a single GP.
The deputy chair of the British Medical Association's GP committee Dr Richard Vautrey said: “These figures show that there has been woefully inadequate progress towards recruiting more GPs to cope with rising patient demand. The government is simply not on course to recruit the extra 5,000 GPs it promised at the last election.
“Large areas of the country are still facing shortages in staff which combined with falling budgets have left many GP practices struggling to provide even basic care to their patients. It is vital that the government urgently implements its promises to properly invest in general practice so that we can recruit and retain enough GPs to deliver the service the public deserves.”