BELFAST, Northern Ireland — Traditionally conservative Northern Ireland is about to legalize both abortion and same-sex marriage, a head-snapping about-face that was imposed on the territory by the British Parliament.

The changes, bitterly resisted by anti-abortion and church groups, were mandated in an amendment to a routine bill on governance of Northern Ireland that Parliament passed in July amid a power vacuum created by the collapse of the region’s governing assembly nearly three years ago.

The amendment will go into effect at midnight on Monday, weeks after the High Court in Belfast rebuffed a legal challenge, ruling that Northern Ireland’s 158-year-old abortion laws are incompatible with the United Kingdom’s human rights commitments.

The judgment was a major victory for women’s rights activists, who had felt left behind after the Republic of Ireland voted to legalize abortion last year. Although Northern Ireland is a part of the United Kingdom, and the majority of its people say they would like abortion to be made available, the regional power-sharing government had blocked abortion reform before collapsing in 2017 over sectarian divides.