PARIS — After a debate lasting nearly two and a half years, France’s Parliament on Wednesday approved a bill to discourage prostitution by penalizing those who pay for sex, following the example of Sweden and Norway.

The National Assembly, France’s lower house of Parliament, voted 64 to 12 for the bill, with the vast majority of the 577 Assembly members not voting. Parliament can approve legislation without a quorum.

The French Socialist government, which had backed the bill, hailed the new law as a victory.

Prime Minister Manuel Valls posted a message on Twitter saying the vote was “a major advance” for the rights of women.

The minister for women’s rights, Laurence Rossignol, told the National Assembly before the vote that prostitution was “violence done to women” and that the new measure would send a message to those who work as prostitutes that “the state, the Parliament and society finally recognizes fully the violence of the system of prostitution.”