Sports Direct has halted the litigation after claiming a breach of confidentiality in relation to a commercial deal.
Mr Justice Peter Smith approved the discontinuation of the claim at a High Court hearing in London on Wednesday.
He told lawyers that the case had been a "ridiculous piece of litigation".
The litigation had been running for nine months and a trial was scheduled for next week.
Mr Justice Smith had already cleared Rangers' chairman Dave King of committing contempt of court, following allegations made by Mr Ashley.
He had also torn a strip off Sports Direct at a preliminary hearing last month - complaining that bosses had abused court processes.
Lawyers for Sports Direct say the firm will cover all lawyers' bills run up during the dispute. The judge was told that total legal costs were estimated to be around £400,000.
A lawyer representing Rangers said after the hearing that club bosses were "pleased".
Ryan Mowat, a partner at law firm Kingsley Napley, said the claim had been "spurious" and added: "Fortunately, the judge has been alive to the game playing of Sports Direct which has helped expose the case for what it was."