A state-funded Islamic school in Birmingham unlawfully discriminated against pupils when it separated them by sex from age nine, a court has been told.

The court of appeal case could lead to other schools that practise similar segregation across the country having to make drastic changes to how they operate, or to split into separate single-sex schools.

The schools inspectorate, Ofsted, alleged that segregating pupils within a mixed-sex school was unlawful discrimination as it launched an appeal against a November 2016 judgment, in which the high court found that segregation did not mean either boys or girls were treated unfavourably.

In an inspection in June 2016, Ofsted rated Al-Hijrah, a school in Birmingham that has pupils aged four to 16, with its lowest grade of “inadequate” and said it should enter special measures. It was partly on the grounds that from the age of nine boys and girls were separated for all lessons, breaks, school trips and other activities.

Other concerns included finding books in the library that condoned violence against women and criticisms of record-keeping and safeguarding.

The school challenged the inspection’s findings in a judicial review at the high court last November. The judge, Mr Justice Jay, found that neither girls nor boys were treated less favourably by being segregated. “There is no evidence in this case that segregation particularly disadvantages women,” he said.

Jay agreed with a recommendation to put the school in special measures on the basis of other issues raised and disagreed that Ofsted’s inspectors had been biased. He allowed the rest of the report to be published, although Al-Hijrah was anonymised as School X.

The case reached the court of appeal on Tuesday, with Ofsted contesting Jay’s ruling that the segregation amounts to lawful discrimination.

The education secretary, Justine Greening, is supporting aspects of Ofsted’s case. Her barrister, Martin Chamberlain, said that while many schools practised some form of gender segregation, it did not mean they would have to close if Ofsted were to win the case.

“The department will work with those schools … to assist them to regularise their position. One option is for the schools to become a single-sex school or to split into two single-sex schools.”

Ofsted’s lead barrister, Helen Mountfield, argued in court that although boys and girls might not receive less favourable treatment generally, “there is discrimination against individual girls and boys at this school, because a girl who wishes to socialise with a particular boy, but can’t, is treated less favourably”.

Mountfield gave the example of a “little gang” made up of both boys and girls who were close friends in the early years of primary school but were split up on grounds of their sex on entering year five.

She said: “There’s a particular detriment to girls ... if boys and girls in a school which is registered as a mixed-sex school lose the opportunity to work and socialise competently with members of the opposite sex and, as Ofsted says, they do go into the world unprepared for life in modern Britain, where they are expected to be able to work and socialise with members of the opposite sex. This imposes a particular detriment to girls as the group with a minority of power in our society.”

The segregation deprived girls of the ability to feel “comfortable and natural” around boys, she said.

Equalities legislation allows for entirely single-sex schools, or schools where the opposite sex is only allowed into sixth form. Within mixed-sex schools equality legislation allows some separation of classes, such as to allow pupils to ask frank questions in sex education, or to address an imbalance, such as running girls-only design and technology classes if it is felt it will encourage more girls to take up the subject.

The law allows for some religious separation, Mountfield said, such as in faith schools. But she added: “Once you’ve got a girl in your school, you can’t then subject her to discrimination in the education, the services, or the facilities you give her.”

Some pupils told inspectors they had no problem with the segregation, but others said they would prefer to be allowed to mix with members of the opposite sex, she told the court.

In the high court hearings, Al-Hijrah school argued that the gender segregation was one of its defining characteristics, and that the policy was clear to parents who wished to send their children there and to previous Ofsted inspectors, who had never raised it as a concern.

As well as the Department for Education, the Equality and Human Rights Commission and the activist group Southall Black Sisters are intervening in the case.

The two-day hearing continues.