ROME — After decades of struggle by gay rights groups, and months of contested political negotiations, the Italian Parliament on Wednesday evening gave final approval to a law recognizing civil unions of same-sex couples.

The vote — 372 to 51, with 99 abstentions — was followed by long applause in the Chamber of Deputies, the lower house of Parliament. At the Trevi Fountain in Rome, people with rainbow flags gathered to celebrate.

It was a historic occasion for a nation that is still dominated by the Roman Catholic Church, which opposed the measure, and where traditional family norms are still strong. It was also a victory for Prime Minister Matteo Renzi, who supported the bill.

Nearly every Western country has legalized same-sex marriage or some form of civil union for gays and lesbians. Italy was perhaps the most prominent exception, and the issue has generated considerable controversy.

Proponents of same-sex unions have complained that the law falls short of granting full equality to same-sex couples. In particular, it does not recognize same-sex marriages. It will not allow someone in a same-sex civil union to legally adopt his or her partner’s biological child. A so-called stepchild adoption provision was opposed by center-right parties and by the church and was ultimately dropped from the legislation.

The Senate approved the bill in February, but a final vote in the lower house was required for the legislation to take effect. Earlier on Wednesday, the government won a vote of confidence, 369 to 193, that it had called on Tuesday, tying its fate to the legislation.

Advocates called the lower house decision historic.

“The wall erected mostly by the Vatican against civil rights in this country has fallen, so it is a historically and politically important moment,” said Franco Grillini, the honorary president of Arcigay, an advocacy group, and a gay-rights advocate. At the same time, same-sex couples in Italy wanted marriage equality, a right held by their counterparts in the United States and many Western European countries, and he said that struggle would continue.

It has been nearly 30 years since lawmakers first proposed giving legal recognition to civil unions in Italy. The Vatican under Pope Francis, while expressing more liberal positions on some social issues, has kept up steadfast opposition to legal recognition of same-sex couples, influencing some italian lawmakers.

Mr. Renzi pledged early on that his government would right what was widely seen as an injustice. There was pressure, too, from the European Court of Human Rights, which ruled last July that Italy’s failure to recognize same-sex unions violated the European Convention on Human Rights.

A first draft of the law — it also grants certain new civil rights, like access to public housing, to all unmarried couples, including heterosexual ones — was watered down when the Senate adopted it in February, after it lost the support of a crucial party faction, and the government had to scramble for votes among more conservative lawmakers. The scrapping of the stepchild adoption clause was part of the resulting compromise.

Some scholars said the controversy revealed Italian lawmakers to be more conservative than their constituents.

“The Italian population metabolized the recognition of same-sex couples some time ago,” said Chiara Saraceno, a noted sociologist who retired as a professor of sociology at the University of Turin, citing a 2009 study that confirmed that a “wide majority” of Italians favored legal recognition of same-sex partnerships, though not gay marriage.

Italian lawmakers “have always lagged behind when it comes to family issues,” Professor Saraceno said, whether because of traditionalist viewpoints or fear of irritating the church. “The Italian population is ready for this,” she said of the legislation.

While many supporters said on Wednesday that the new law was better than nothing, many remained bitter.

“This law is born as an old law, that should have been voted 20 years ago,” when civil unions began to be legally recognized in other countries, said Michela Marzano of the Democratic Party, who noted the law’s shortcomings.

“Italy remains a culturally backward country where the only possible family” is still the traditional one, she said. “It prefers to penalize children rather than recognize the multifaceted families that already exist.”

President Sergio Mattarella has a month to sign the legislation, a step that is usually a formality.

Correction:

Because of an editing error, an earlier version of this article gave an outdated position for Chiara Saraceno. She has retired; she is no longer a professor of sociology at the University of Turin.

Correction:

An earlier version of the above correction omitted the source of the error. It was made during the editing process, not by the reporter.

A version of this article appears in print on , on Page A9 of the New York edition with the headline: Same-Sex Civil Unions Gain Approval in Italy. Order Reprints | Today’s Paper | Subscribe