An Islamic faith school which had books in its library that were incompatible with "fundamental British values" has lost its High Court bid to overturn an Ofsted report placing it in special measures.

But a judge said the school watchdog's report from June cannot be published in its current form because Ofsted was wrong to conclude that the school's policy of segregating the sexes constituted unlawful discrimination.

In the first case of its kind involving a faith-based school, the judge said: "There is no evidence in this case that segregation particularly disadvantages women."

However special measures were justified because "offensive books in the school library" clearly treated women "as subordinate to men", said the judge.

The judge said: "In my judgment it is obvious that leaders at the school conspicuously failed in allowing these books to enter, or re-enter, the library and the report's assessment to that effect cannot be impugned."

The school, which must not be identified, is a voluntary-aided school for boys and girls aged between four and 16, with a policy of segregation of the sexes from Year 5.

Because of the public importance of the case, the judge gave Ofsted and the school's interim executive board permission to take a challenge against his ruling to the Court of Appeal.

Mr Justice Jay, sitting in London, said James McNeillie, Ofsted's lead inspector at the school, had reported finding the offensive books in the school library.

The books, published between 1993 and 2009, "contained views which are inimical to fundamental British values".

One of the books said "a wife is not allowed to refuse sex to her husband" and another "that women are commanded to obey their husbands and fulfil their domestic duties", said the judge.

Two books made clear that a husband might in certain circumstances beat his wife, "provided that this is not done 'harshly'".

One of the books was prominently displayed in the library, said the judge, but it was apparent to Mr McNeillie that the head teacher was not aware the books were available and "to be fair to him said their content was 'abhorrent'".

Inspectors were told that, after an earlier inspection, unsuitable texts had been removed.

In a summary of his judgment, the judge said he had criticised Ofsted for finding in its latest report that there was a leadership and management failing at the school in relating to segregation on the grounds of sex when no criticism of the policy had been made for a number of years.

However the school was not entitled to have the report quashed because of the other "concerns" over the safeguarding of children.

The judge acquitted the Ofsted inspectors of actual or apparent bias, and lead inspector Mr McNeillie of allegations that he approached the inspection exercise with a closed mind.

Later the chief inspector of schools, Sir Michael Wilshaw, said: "We are pleased that the court has rejected the unfounded claim that Ofsted unfairly singled out this school and that our conduct in relation to this inspection was biased.

"We also note that the judge has accepted that we found other serious concerns, including safeguarding, during this inspection that were unrelated to the segregation issue.

"It is our intention shortly to publish a revised inspection report for this school.

"We are, however, disappointed that the court has determined that the practice of completely segregating boys and girls in this publicly funded mixed-sex school does not amount to unlawful discrimination.

"I do not believe that segregating children without an educational reason is in their best educational interests. Ofsted has obtained permission from the judge to appeal this judgment.

"I believe the matters that went before the court are of great public importance and have far-reaching implications for our schools and for our society.

"In making their judgments on the evidence and against our published inspection criteria, I always expect Her Majesty's inspectors to ask themselves whether they are acting reasonably. I strongly believe that they did so in this case.

"As a society, we expect men and women to integrate freely and fully both in the workplace and in social settings.

"Here was a mixed-sex school where children were being kept apart on the grounds of gender. This segregation took place in all lessons, in the corridors, during breaks and lunchtimes and for all social and extracurricular activities.

"Ofsted is charged with inspecting how well schools are promoting British values.

"In this respect, it was entirely reasonable for inspectors to consider whether a regime that denied boys and girls in a mixed school the opportunity to interact and socialise together was discriminatory and was failing to adequately prepare them for life in modern Britain after they leave school."