An Ontario court has struck down a provincial government order that made some post-secondary student fees optional.

Last December, Premier Doug Ford's cabinet approved the order and later put it into effect in what it called the "Student Choice Initiative."

The Canadian Federation of Students and York Federation of Students filed a legal challenge, arguing the move was a politically motivated attack on student unions and services that threatened university independence.

The groups said the change was arbitrary and threatened student-led programs such as clubs, campus newspapers, food banks and other support services, and part-time jobs.

The government contended that students should have more choice as to which campus services they support.

In its unanimous ruling, the Ontario Superior Court of Justice Divisional Court said the government's decision to enact the policy was beyond its legislative authority.

"Requiring that universities allow students to opt out of student association fees and other "non-essential" services is inconsistent with the universities' autonomous governance," a panel of justices said in the ruling released on Thursday.

The Canadian Federation of Students and the York Federation of Students said they would hold a joint news conference Friday to respond to the ruling.

"Today the Ontario Divisional Court has confirmed what students already knew: The Student Choice Initiative is unlawful, and the Ford government acted beyond their authority," Kayla Weiler, a CFS representative, said in a release.

"Doug Ford's attempt to wipe out students' unions under the guise of giving students 'choice' has been exposed for what it really was: an attempt to silence his opposition."

Jenessa Crognali, press secretary for Attorney General Doug Downey's office, said the ruling is being reviewed.

"As this matter is in the appeal period, it would be inappropriate to comment," she wrote in an email.

Full-time students in Ontario pay about $300 in fees each year, none of which goes to the institutions themselves.

Last month, York University estimated that 60 per cent of such fees -- about $1.25 million -- were made optional.

The government had threatened to claw back operating grants to schools that didn't abide by its directives.