I am sitting in the back of an unmarked police car on the small island of Skeppsholmen, to the east of Stockholm's picturesque old town. Above us is the city's modern art museum but it's a dark February night and we're not here to appreciate culture. "They park up there," says the detective in the front passenger seat, pointing to a car park at the top of the hill. "We wait a few minutes and then we leap out, run up the hill and pull open the doors."

What happens next is a textbook example of the way Sweden's law banning the purchase of sex works in practice. The driver of the car, who's brought a prostituted woman to the island to have sex, is arrested on the spot. He's given a choice: admit the offence and pay a fine, based on income, or go to court and risk publicity. The woman, who hasn't broken any law, is offered help from social services if she wants to leave prostitution. Otherwise, she's allowed to go.

"Buying sex is one of the most shameful crimes you can be arrested for," explains the detective, Simon Haggstrom. He's young, black, and his appearance – shaved head, baggy jeans – suggests a music industry executive rather than a cop. But he's in charge of the prostitution unit of Stockholm county police and he's proud of the fact that he's arrested more than 600 men under the Swedish law: "We've arrested everyone from drug addicts to politicians. Once I arrested a priest and he told me I'd ruined his life. I told him, 'I haven't ruined your life, you have.'"

Download the new Independent Premium app Sharing the full story, not just the headlines

Sweden's decision to reverse centuries of assumptions about prostitution and criminalise buyers of sex caused astonishment when the law came into force in 1999. As arguments raged elsewhere about whether prostitution should be legalised, the Swedish government's simple idea – that the wrong people were being arrested – was new and controversial. Detective Superintendent Kajsa Wahlberg is Sweden's national rapporteur on trafficking in human beings. When I meet her at her office in Stockholm, she recalls that one police officer from another country actually accused the Swedes of "Nazi methods". Wahlberg acknowledges that many Swedish officers were sceptical as well. "There was frustration and anger within the police. People were chewing on lemons," she says with a wry laugh.

All of that's changed dramatically since the law came into effect. "The main change I can see when I look back is we got the men on board," says Wahlberg. "The problem is gender-specific. Men buy women. One of the keys is to train police officers. When they have understood the background, they get the picture." She talks about why women end up in prostitution, citing research that shows a history of childhood sexual abuse, compounded by problems with drugs and alcohol.

"They have no confidence in themselves. They've been left out and neglected and try to get all kinds of attention. This is not about an adult woman's choice." In the 1990s, the Swedish government accepted the arguments of women's groups that prostitution is a barrier to gender equality and a form of violence against women.

What's remarkable is that public opinion, which was initially hostile, has swung round to this view; these days, 70 per cent of the public support the law. "We've changed the mindset of the Swedish population," Haggstrom tells me. The change is visible among the older members of his unit.

One undercover cop, who's been a police officer for 37 years, reveals a lingering sense of surprise when he remembers what happened 14 years ago. "When the law came into force, the streets were empty for six months," he says.

These days he's one of its most enthusiastic supporters, having seen for himself how the number of women in street prostitution in Stockholm has declined. Where 70 or 80 women used to sell sex outdoors, these days it's between five and 10 in winter, 25 in summer. A small number of women work on the streets of Malmö and Gothenburg but the Swedish figures are nothing like those for Denmark, where prostitution has been decriminalised. Denmark has just over half the population of Sweden but one study suggested there were more than 1,400 women selling sex on Danish streets.

The law has brought about other changes as well. Before 1999, most women in street prostitution in Stockholm were Swedish. Now they're from the Baltic states or Africa, and have sold sex in other countries as well. They tell Haggstrom's officers they're much more likely to be subjected to violence in countries where prostitution has been legalised.

"Swedish men want oral sex and intercourse, nothing more than that," the undercover cop tells me. "They know they have to behave or they may be arrested. They don't want to use violence."

It's a fascinating observation because one of the criticisms of the law was that it would make prostitution more dangerous. All the Swedish police officers I spoke to insisted this was a myth, along with the notion that prostitution would go underground. "If a sex buyer can find a prostituted woman in a hotel or apartment, the police can do it," Haggstrom observes sardonically.

"Pimps have to advertise." Specialist officers have been trained to monitor the internet and the police also have access to telephone intercepts, which suggest that traffickers no longer regard Sweden as a worthwhile market. "We've had wiretapping cases where pimps say they don't find Sweden attractive," Haggstrom continues. "Even if they don't get arrested, we arrest the clients. They're in it for the money. For me, this is not an advanced equation to understand."

Swedish crime statistics seem to support his argument. In 2011, only two people were convicted of sex trafficking and another 11 for pimping connected to trafficking. (At the same time, 450 men were convicted and fined for buying sex, including a number of foreign tourists). Last year the figures were slightly higher: three convictions for sex trafficking and 32 for the related offence. But 40 women, mostly from Romania, had sufficient confidence in the Swedish criminal justice system to testify against the men exploiting them

Could the Swedish law work in other countries? Norway and Iceland have brought in laws banning the purchase of sex and the UK has taken tentative steps towards criminalising clients; it's already a criminal offence to buy sex from anyone under the age of 18 or an adult who's being exploited by pimps or traffickers. But there have been few convictions, suggesting that British police officers don't share the robust attitudes of their Swedish counterparts. Haggstrom agrees with Wahlberg that legislation on its own isn't enough: "You have to have enforcement resources. You have to have police officers who go out and make arrests."

In the police car, something happens which reveals the full extent of the philosophical shift that has affected men and women in Sweden. In a brightly lit street, Haggstrom points out a couple of Romanian women who work as prostitutes. As I think about them making the journey over the bridge with a total stranger to the desolate car park on Skeppsholmen, Haggstrom turns to me. "Having sex is not a human right," he says quietly.