Chilean lawmakers have approved a bill that recognizes civil unions between same-sex couples.

The bill has now been passed by both houses of congress in the South American country, and goes to President Michelle Bachelet for final approval.

The legislation has been in the works for four years and will give same-sex and unmarried couples many of the rights granted to married couples.

Civil unions have been recognized in several countries across South America, but conservative Chile has been slower to change. It decriminalized gay sex in 1999 and the killing of a gay man in 2012 set off a national debate that prompted Congress to pass a hate crimes law.