A court in Canada has ordered protesters in a Vancouver neighbourhood to stop interfering with efforts to build temporary accommodation for the homeless, bringing an end to a bitter debate triggered by the city’s housing crisis.

“We respect people’s rights to protest, but blocking the construction of much-needed housing for the homeless is not something the city can accept,” Gregor Robertson, the mayor of Vancouver, said in a statement responding to the court’s decision.

Controversy erupted after the city announced earlier this year that a 78-unit project would be built in Marpole, a neighbourhood in south Vancouver. The development is part of a wider effort to create 600 units of temporary housing across the city, as Vancouver grapples with record levels of homelessness.

Protesters – armed with placards and posters and swelling to as many as 200 people at times – began descending on the site. Some pointed to the project’s proximity to nearby schools, including an elementary school across the street. Others highlighted plans for a mix of tenants that they said could include people with an extensive criminal history and a high risk of reoffending.

“We’re not against modular homes for the homeless people, that is not the issue. It’s just that the location is very, very wrong,” one protester told CTV News. “It’s so close to vulnerable children. Kids were out during recess and they came up to the fence,” noted another.

A homeless woman lies on a Vancouver street. Photograph: Andy Clark / Reuters/REUTERS

The city said the site, which would be tailored for people aged 45 and over, would be managed 24 hours a day, seven days a week, by an agency with experience in supportive and low-income housing. It had struck a five-year contract with a developer to use the land, after which it would either extend the contract or seek to move people into permanent housing.

Last week the city said that construction of the project was being delayed by several protesters who were physically blocking entrance to the site. After infraction notices did little to dissuade the protesters, the city said it had been forced to file a demand for an injunction.

The injuction issued by a British Columbia supreme court judge prohibits anyone from loitering on nearby streets or sidewalks. While the city welcomed the decision, it noted that the delays could mean the homes may not be ready for tenants before the end of winter.

News of the injunction prompted some two dozen people – including students from a nearby high school – to turn up at the site on Tuesday to show their support for the project.

The debate over the project comes as Vancouver, which ranks as one of the world’s least affordable housing markets, is in the grips of a housing crisis. Despite a 15% tax levied last year on foreign buyers, a typical home in the greater Vancouver region costs C$1m, placing it out of reach for many in a city where the median household income is C$79,930. Rental vacancy rates have dropped below 1% while the number of homeless people in the city has increased 30% since 2014.