Nigeria's President Goodluck Jonathan signed a bill on Monday that criminalises same-sex relationships, defying western pressure over gay rights and provoking US criticism.

The bill, which contains penalties of up to 14 years in prison and bans gay marriage, same-sex "amorous relationships" and membership of gay rights groups, was passed by the national assembly last May but Jonathan had delayed signing it into law.

A presidential spokesman told Reuters he had now done so. As in much of sub-Saharan Africa, anti-gay sentiment and persecution of homosexuals is rife in Nigeria, so the new legislation is likely to be popular. Jonathan is expected to seek re-election in 2015 but is under pressure after several dozen lawmakers and a handful of regional governors defected to the opposition in the past two months.

Under existing Nigerian federal law, sodomy is punishable by jail, but this bill legislates for a much broader crackdown on homosexual people, who live a largely underground existence.

The US secretary of state, John Kerry, said Washington was deeply concerned by the new measures.

"Beyond even prohibiting same sex marriage, this law dangerously restricts freedom of assembly ... and expression for all Nigerians," he said in a statement.

"It is inconsistent with Nigeria's international legal obligations and undermines … democratic reforms and human rights protections," he said.

While European countries, most recently France, have moved to offer same-sex couples the legal rights enjoyed by heterosexuals, many African countries are seeking to tighten laws against homosexuality.

Britain and some other western countries have threatened to cut aid to governments that pass laws persecuting homosexuals, a threat that has helped hold back or scupper such legislation in aid-dependent nations such as Uganda and Malawi. But they have little leverage over Nigeria, whose budget is funded by its oil output of 2m barrels a day .

"Persons who enter into a same-sex marriage contract or civil union commit an offence and are each liable on conviction to a term of 14 years in prison," the bill says.

"Any person who registers, operates or participates in gay clubs, societies and organisations or directly or indirectly makes public show of same-sex amorous relationship in Nigeria commits an offence and shall each be liable on conviction to a term of 10 years in prison."

The news provoked an outpouring of anti-gay invective on Twitter.