MADRID -- Spain has raised the minimum age for marriage from 14 to 16 to boost protection of minors and bring the country in line with its European Union neighbors.

The legislation came into effect Thursday and follows recommendations from United Nations experts and child protection groups.

Spanish law had previously allowed boys and girls to marry at 14 with permission from a judge.

Get Breaking News Delivered to Your Inbox

It was one of lowest minimum ages in the European Union, with most members setting it at 16.

The change will affect few as national statistics show only a handful of 14-year-olds were getting married each year.

Spain also recently raised the minimum age for consent to sexual relations from 13 to 16.