Spain is to raise the age of consent from 13 to 16 and the minimum age for marriage from 14 to 16.

The change was agreed unanimously in principle by parliament in 2009 under the previous government and is expected to come into force this month.

Adults who have sex with underage children now face from two to six years in prison and up to 12 years if they have performed oral or penetrative sex.

An exception is made in the case of consensual sex with someone under 16 "when the other party is of a similar age or stage of development and maturity", a loose concept that judges will have to define on a case-by-case basis.

Raising the age to 16 brings Spain into line with the UK, Russia, the Netherlands, Norway and Belgium. It is 14 in Germany, Austria, Hungary, Italy and Portugal and 18 in Turkey and Malta.

In most European states the law does not specify whether the acts are heterosexual or homosexual.

Teenage marriage is rare in Spain – only four boys and 64 girls under 17 married in 2010 – but in a national survey published two years ago 74% of women born since 1971 said they had lost their virginity before they were 20, nearly twice as many as their mothers' generation.

The rate of teenage pregnancy is low, less than a third of that in the United States. However, a report on sexual health in Spain published on Wednesday said all forms of sexually transmitted diseases are on the rise.

All Spanish children receive sex education classes in the last year of primary school, when they are 11.

But under the new education law proposed by Spain's rightwing government, sex education will be removed from the curriculum.

"Spain has advanced a lot in a short period of time," said Ezequiel Pérez Campos, president of the Spanish Contraception Society. "We have overcome many fears and taboos and women now play a much more central and active role."