Year after year, Los Angeles has forced hundreds of illegal or “bootlegged” apartments to be shuttered, even as local politicians bemoan a housing crisis.

Now the city is easing the way to legalize such apartments, a plan long championed by an unusual alliance of landlords and tenant activists.

The Los Angeles City Council voted Wednesday to approve a new law that smooths the way for landlords to get approval for bootlegged apartments — existing units that were created without the city’s blessing — if they guarantee affordable housing on the site.

Councilman Jose Huizar heralded it as a step that would add affordable units and bring existing housing “out of the shadows.” He stressed that the apartments still would need to