Image copyright Trinity Western University Image caption The university expects to enrol its first class of law students in 2016

Canada's top court has ruled in favour of denying accreditation to a Christian law school that banned students from having gay sex.

Friday's ruling against Trinity Western University in British Columbia (BC) was closely watched by both religious freedom and gay rights advocates.

The university made students promise not to have extra-marital or gay sex.

The Supreme Court found that protecting LGBT students from discrimination trumped religious freedom.

The evangelical university finalised its proposal for a law school in 2012 and applied for accreditation in every province so that its students could be called to the bar anywhere in Canada.

Ontario, British Columbia and Nova Scotia law societies denied the school accreditation, on the grounds that it required all students to sign a covenant binding them to a code of conduct which banned sex outside the confines of heterosexual marriage.

Lower courts in Nova Scotia and British Columbia sided with the university, but Ontario sided with the law society and upheld the organisation's right to deny the school accreditation.

The case went all the way to Canada's top court, and the ruling was viewed as a key victory for LGBT rights advocates.

The court found that supporting diversity in Canada's legal profession, and protecting the safety of LGBT students, was more important than the school's right to religious freedom.

"The (law society of British Columbia) has an overarching interest in protecting the values of equality and human rights in carrying out its functions," the court ruled. "Approving or facilitating inequitable barriers to the profession could undermine public confidence in the (law society's) ability to regulate in the public interest."