Electric shock collars for cats and dogs will be banned in England, the government has announced.
The training devices deliver up to 6,000 volts of electricity or spray noxious chemicals to control animals' behaviour.
Environment secretary Michael Gove said this causes unacceptable "harm and suffering".
Animal charities, many of which had campaigned for the change in the law, welcomed the move.
However, some supporters of the controversial collars accused Mr Gove of making a "complete 180" after his department initially suggested there was insufficient evidence for a ban earlier this year.
A survey by the RSPCA found that 5% of dog owners reported using shock collars, suggesting that hundreds of thousands of animals would be affected by the ban.
While it supported a ban, the RSPCA criticised the decision to continue to allow electric containment fences.
A spokeswoman said: "In modern day society there is no excuse or need for the use of devices which can compromise cat and dog welfare, especially when humane and viable alternatives to training and containing dogs and cats are available."
The Dogs Trust said that electric collars could send shocks of 100 to 6,000 volts for up to 11 seconds at a time.
Dr Rachel Casey, director of canine behaviour and research at the Dogs Trust: "Scientific research has demonstrated that electronic devices which deliver an aversive stimulus have a negative impact on dog welfare, so this ban will have a major positive impact for dogs in the UK."
A ban on the devices was backed by 74% of people in a 2014 poll by the Kennel Club.
The dog welfare organisation said a ban would ensure that pets were trained with "positive methods, free from pain".
The announcement follows a government consultation, in which half of the 7,000 responses said they did not want to see containment fences banned.
BREAKING NEWS!— The Kennel Club (@TheKennelClubUK) August 27, 2018
We’re thrilled to announce that the Government are banning the use of electric shock collars across the UK.
It’s been a hard-fought campaign for us, starting over 10 years ago; but today’s news will ensure dogs are trained using positive methods, free from pain. pic.twitter.com/toQMel3azo
Mr Gove said: "We are a nation of animal lovers and the use of punitive shock collars cause harm and suffering to our pets."
He urged pet owners to use "positive reward training methods" instead.
However, a letter sent from Mr Gove's department in February to the Royal Veterinary College - seen by the Press Association - suggested that there was insufficient evidence for supporting a ban.
Dog trainer and campaigner Jamie Penrith said Mr Gove had made an "abrupt" policy turnaround with no additional evidence.
Ian Gregory, a lobbyist for pet collar manufacturers, campaigned to prevent the ban on containment fences, arguing that they helped prevent some of the 300,000 deaths of cats in road accidents.
He said that animal charities exaggerated the impact of the shock delivered by a collar, which was about a millijoule of energy, compared to cattle fencing which was a thousand times more powerful.
"The anecdotal problems reported with pet collars can be resolved by product standards rather than by banning a proven technology," he said.
"The hundreds of thousands of dog owners using remote trainers do not deserve to be criminalised."