The lower house of parliament voted to change the Swiss penal code to make it illegal to pay for sex with a minor, following suit after the upper house adopted the bill.
The federal government had previously promised to bring in the change.
Until now, paying for sex with people above 16 — the legal age of consent in Switzerland — was legal in the country.
With the law change, prostitutes between the ages of 16 and 18 will not face penalties, but clients who pay for sex with minors will face up to three years behind bars.
Anyone encouraging prostitution by minors, including pimps, and people running brothels or escort services, will face up to ten years in prison.
The law change also raises the legal age to participate in pornography, making it a crime punishable by up to five years in jail to produce, import, promote, screen or possess pornography featuring minors.
The parliament's decision was needed for Switzerland to implement a European Council convention on the protection of children that it signed in 2010.
"It is important that the protection of children is not limited by borders and can be ensured across the entire European territory," Socialist lawmaker Margret Kiener Nellen told the house ahead of Tuesday's vote, according to the ATS news agency.
Prostitution is legal and regulated in Switzerland, where it is considered a legitimate form of economic activity.
Prostitutes can ply their trade openly in specific areas of some cities, as well as in brothels or through escort services, as long as they haver proper work permits and pay taxes and social charges on the money they make.
Last month, prostitution in Switzerland made global headlines when Zurich opened the country's first sex "drive-in", on the outskirts of town, in a bid to create a safer space for sex workers and remove the trade from the city centre.