A law banning puppy and kitten farming, which campaigners hope will end the practice by some unscrupulous breeders of keeping animals constantly pregnant and often in dirty and cramped conditions, is to be laid by the government.

The change, expected to come into force in April 2020, will mean young cats and dogs can no longer be sold by a pet shop or commercial dealer unless they have bred them.

Would-be pet owners will need to deal directly with breeders or rehoming centres, though some campaigners have called for the law, to be laid on Monday, to go further and clamp down on the practices of animal sanctuaries.

The unethical practice of puppy and kitten farming is said to lead to the animals being taken from their mothers after only a few weeks, which puts them at risk of disease and behavioural issues.

The campaign has been backed by celebrities and charities including the RSPCA and Battersea Dogs and Cats Home.

The Downton Abbey actor Peter Egan, an animal rights campaigner who has promoted the law, called it “the most exciting change in animal welfare legislation for years”.

The legislation is being named after a Cavalier King Charles spaniel called Lucy, who died in 2016 after being forced to repeatedly give birth in terrible conditions on a Welsh puppy farm.

The environment secretary, Michael Gove, said he wanted to ensure no other animal suffers the same fate. He said the law would put an end to the early separation of puppies and kittens from their mothers.

“I would like to thank the tireless campaigners and animal lovers who have helped to bring about this positive change,” Gove said. “This is all part of our plan to make this country the best place in the world for the protection and care of animals.”

Marc Abraham, the founder of Pup Aid, which campaigned for the law change, said: “‘Lucy’s law’ is named after one of the sweetest, bravest dogs I’ve ever known, and is a fitting tribute to all the victims of the cruel third-party puppy trade, both past and present.”

The decision to ban commercial third-party sales was announced in December and follows years of campaigning. More than 95% of responses to the government’s public consultation expressed support for a ban.

The legislation will come into force on 6 April 2020, which the Department for Environment, Food and Rural Affairs said would give the pet industry and consumers time to prepare for the change.