TORONTO -- An Ontario court says doctors who have a moral or religious objection to treatments such as assisted dying, contraception or abortions have to refer patients to another doctor who can provide the service.

A group of five doctors and three professional organizations had launched a legal challenge against a policy issued by the province's medical regulator, arguing it infringed on their right to freedom of religion and conscience under the Charter of Rights and Freedoms.

The group -- which includes the Christian Medical and Dental Society of Canada, the Canadian Federation of Catholic Physicians' Societies and Canadian Physicians for Life -- said the requirement for a referral amounted to being forced to take part in the treatment.

But the College of Physicians and Surgeons of Ontario said the policy aims to balance the moral beliefs of individual physicians while nonetheless ensuring access to care, particularly for vulnerable patients.

In a ruling released Wednesday, the divisional court said that though the policy does limit doctors' religious freedom, the breach is justified.

The court said the benefits to the public outweigh the cost to doctors.

"The goal of ensuring access to health care, in particular equitable access to health care, is pressing and substantial. The effective referral requirements of the policies are rationally connected to the goal," Justice Herman J. Wilton-Siegel wrote on behalf of the three-member panel.

"The requirements impair the individual applicants' right of religious freedom as little as reasonably possible in order to achieve the goal. The alternatives proposed by the applicants would compromise the goal of ensuring access to health care in many situations, often involving vulnerable members of our society at the time of requesting medical services."

The advocacy group Dying With Dignity, which was an intervener in the case, said the ruling is a victory for patients.

"We believe the effective referral policy strikes a fair, sensible balance between a physician's right to conscience or moral objection and a patient's right to care. We are grateful that the judges' decision puts patients first," the organization's CEO, Shanaaz Gokool, said it a statement.