London Metropolitan University has been given permission to challenge a ban on its recruitment of overseas students.
The High Court also ruled that existing students with full immigration status should be allowed to continue their studies.
Last month the UK Border Agency took away the university's right to sponsor students for UK visas.
It said the university was not making proper checks.
About 2000 students were affected.
They were told they had to find alternative courses at other universities or leave the UK. Many were about to begin the second or third year of their courses.
The UK Border Agency is cracking down on alleged abuse of the student visa system and London Met was the first university to lose its right to sponsor students from outside of the European Union for their visas.
It said the university had failed to address "serious failings" in its system which had been identified more than six months ago.
At the High Court in London, Richard Gordon for London Met had said the issue "came down to fairness".
He said there was a strong case that the UKBA's decision was unlawful and a temporary injunction (suspension of the ban) should be granted, given the impact of the decision on the university and its students.
Mr Justice Irwin refused that request but did give the university permission to mount a full legal challenge in the form of a judicial review and made temporary orders protecting some students.
He said that existing overseas students and ones who are due to start this term would be allowed to start or continue as long as they were already in the UK and had full immigration status, pending a resolution of the issue.
And later on Friday evening the UK Border Agency agreed to allow "existing genuine students" to continue studying at the university "until their course has ended or the end of the academic year, whichever is soonest - as long as they meet the right standards".
A statement from the UKBA added: "But students who are here illegally and do not meet our immigration criteria will not be allowed to stay".
Mr Justice Irwin had earlier told the court the interests of the students needed to be taken in to account.
And referring to students whose visa status was in order, he had said: "I would be interested in respect of such students whether a concession could be made".
The UK Border Agency (UKBA) took away the university's "highly trusted status" at the end of August - meaning it can no longer recruit students from outside the European Union - in a crackdown on alleged abuse of the student visa system.
Overseas students staying more than a year count in the migration figures and the government has pledged to cut net migration to "tens of thousands".
The UK Border Agency has insisted the decision to revoke the visa sponsor licence was correct and says it will continue to fight the university's legal challenge.
In a sample of 101 students, it said, more than a quarter had no permission to be in the UK, while separate checks showed there was no proper evidence that some students spoke good enough English to be given a student visa.
Criticism was also made of the university's attendance checks.
In court, Lisa Giovannetti QC, for the Home Office, said London Met had not deliberately breached the regulations and had made attempts to put things right, but had been unable to do that effectively.
Outside the High Court the university's vice-chancellor, Professor Gillies said the judge's ruling was good for students, who had been hugely confused by the action of the UK Border Agency, and would allow the issue to be looked at in a "sober and serious way".
"It's an important issue and there are lessons for all to learn," he said.
Last week the government pledged £2m to help students affected. A "task force" had been set up to help them find alternative courses.
Third year London Met student Donna Marie Winstanley, from Hong Kong, told the BBC News website she was pleased by the ruling.
"It's really good," she said.
"I have not applied to any other universities. I had a feeling that the university was going to win the case. Most of my classmates have already applied. I didn't want to pay any more money. I had already paid £16,000 in fees for my first two years."
Third year computer science student Ashiqur Rahman from Bangladesh said: "I am very happy if it's true that I can continue my studies at the university, but I am waiting for confirmation".
The National Union of Students has welcomed the ruling. It says the case has huge implications for international students in the UK and others thinking about coming to Britain to study and had asked to give evidence in the case.
Professor Eric Thomas, president of Universities UK (which represents university leaders), said: "This decision should allow some students to be able to finish their courses prior to the main legal proceedings, which is good news.
"This is, however, an opportunity to reflect on how immigration compliance in relation to international students is handled. We must remind ourselves of our duties to international students and ensure that, in future, legitimate individuals who have come to the UK in good faith are not forced to suffer the distress and uncertainty endured by many in recent weeks."