Debenhams' rescue deal with landlords to cut rents and close 50 stores is legal, a judge has ruled.

Commercial landlords funded by Mike Ashley's Sports Direct had taken the department store to court, claiming the terms of the insolvency process known as a Company Voluntary Arrangement (CVA) were unfair.

But Mr Justice Norris told the High Court that four of the five grounds for appeal had failed, and criticised the behaviour of Sports Direct for personal attacks on the integrity of Debenhams' directors.

Mr Ashley had previously called for Debenhams' advisers to "go to prison, given their skulduggery in undermining shareholders and other stakeholders, such as employees and pensioners" after the company refused his offer of a £150 million loan in return for him becoming chief executive.

He said Debenhams "seriously considered" accepting the funds but believed the conditions - including installing Mr Ashley as boss - were "too onerous or impossible to fulfil" especially because Sports Direct owned rival House of Fraser.

The judge added that it was "entirely plausible" that Mr Ashley wanted to buy Debenhams to get "an advantageous price" or "the elimination of a competitor to House of Fraser", which the business tycoon bought last year.

He also said it was plausible that Mr Ashley went to court "to pursue his grievance at the manner in which his attempt to acquire Debenhams pre-administration was frustrated".

Debenhams stores in Barrow, Workington and Carlisle were not among the 22 stores that the chain has previously announced will close by 2020. The remaining 28 stores set to close is yet to be revealed.

In his judgment, Mr Justice Norris added that Sports Direct's arguments that Debenhams had been influenced by a desire to prefer other creditors "did not have legs" and praised Debenhams finance chief Rachel Osborne on her evidence, calling her a "transparently honest and careful witness".

"Dealings were also constrained by the reluctance of Sports Direct to sign up to a non-disclosure agreement" before looking at Debenhams' accounts, he added.

The judge was also scathing about Sports Direct's involvement in the case, in particular, criticising the company for not challenging Debenhams' claim that new funding raised in March was secured debt, rather than unsecured.

He said: "The applicants had the opportunity to advance this case in evidence in reply, but squandered it by seeking to adduce the evidence of a business consultant retained by Sports Direct covering so much of the history concerning Sports Direct's attempts to remove members of the Debenhams board and to have Mr Ashley appointed chief executive, containing such accusations of mismanagement and misrepresentation by the board, and such personal attacks on the integrity of the Debenhams board that it would have been an injustice not to allow them to be tested: yet to permit cross-examination would have derailed the expedited trial. So, I did not admit it."

Debenhams welcomed the judgment, adding the CVA will continue to be implemented.

Chief executive Stefaan Vansteenkiste said: "We note that the only aspect that the judge required to be adjusted was a technical provision of the CVA relating to landlord forfeiture provisions."

Sports Direct was approached for comment.

The applicants will be allowed to appeal and submit short written statements to the court.