Festival-goers who test their drugs at government-sanctioned trial facilities could still be arrested by police after getting their results.
The one-year drug-testing trial in NSW announced on Thursday - five years after a coroner urged the introduction of the harm-reduction measure - will allow revellers at 12 music festivals to check drugs intended for personal use.
But the trial will not change police powers to lay possession charges, nor will it protect drug suppliers.
"Drugs are illegal in the state, yet we've made a decision to allow for pill testing at major music festivals," Premier Chris Minns said.
"There's no law that we can craft that can do both things at the same time, solving effectively for both of those problems ... so the government's made a decision to live with the contradiction, rather than risk someone dying as a result of having it in place."
A sceptic for many years, Mr Minns said he was the last in cabinet to change his mind on pill testing.
The premier was at pains to reinforce that illicit drugs remained illegal in NSW, despite mounting calls from experts for decriminalisation.
"Police will enforce the law ... they've got discretion at the moment about how they apply it, but drugs remain illegal in NSW," he said.
An amnesty zone will apply immediately around testing sites, however, police will still patrol the festivals and can charge those caught with illicit substances.
Jennifer Ross-King, whose daughter Alex died after taking drugs at a music festival in 2019, said she was frustrated with how long it had taken the state to move on testing.
"Alex was a smart young girl and I think she would have used that information and proceeded to come home that night," she said.
"I think this is now the first step to moving forward to make change."
Drug-checking was the top recommendation of a 2019 inquiry into the deaths of six young people at music festivals when coroner Harriet Grahame found evidence to support community- and festival-based services was "compelling".
That recommendation was rejected by the then-Liberal government, which opted instead for amnesty bins at festival entrances.
Unharm co-founder Will Tregoning said the trial was a great step forward and he hoped there might one day be services outside music events.
"Drug use and drug overdoses don't just happen at festivals," he told AAP.
"Even with pill testing, there should be community-based services, just like has happened in Victoria and Queensland.
"It's especially important with the rise in synthetic opioids ... particularly with substances like nitazenes turning up in all sorts of things, from cocaine to cannabis products to nicotine vapes."
Advocates note drug checking offers some users their first chance to discuss the health risks of illicit drug use as they await results.
NSW Police and NSW Health will implement the trial, which will cost more than $1 million to roll out and be independently evaluated.
It's expected to begin as early as February, although that will be after many of the larger summer festivals.
The decision follows interim advice from the NSW Drug Summit held in November and December ahead of a final report due in early 2025.
Health Minister Ryan Park said the interim advice reflected a diverse range of views from experts, frontline workers and drug users, although he repeated the premier's line that drug checking was "no silver bullet".
Opposition Leader Mark Speakman accused the premier of caving to a left wing of the Labor party while adopting anti-testing rhetoric dismissed by the coroner five years earlier.
Victoria announced an 18-month trial of pill testing, which also included a fixed-site service near Melbourne nightclubs, in June.
Both trials are due to conclude around the same time.
Queensland and the ACT already have drug-testing services at fixed sites.