Scientists have used gene editing technology to create female-only and male-only litters of mice.
Their technique could prevent the destruction of hundreds of thousands of unwanted mice used in research.
The team says it could also prevent the slaughter of millions of male chickens in the UK, which are culled because they don't lay eggs.
The government is considering allowing gene editing to be used by the livestock industry in England.
The technique, which has been outlined in the academic journal Nature Communications, deactivates a gene involved with embryo development.
The system can be programmed to kick in for either male or female embryos at a very early stage of development - of between 16 and 32 cells.
The researchers believe that the technique could work on farm animals and they are in discussions to set up scientific pilot studies with the Roslin Institute near Edinburgh, which is among the world leaders in gene editing of livestock.
Dr Peter Ellis of Kent University told BBC News that if the results do translate from the lab to commercial use, they could have a "far reaching" impact on animal welfare.
"Between four and six billion chicks in the poultry industry are killed each year worldwide. In principle, we could set up a system so that instead of having chicks having to be killed after birth when they have a nervous system and potentially capable of suffering, those eggs are laid but simply never hatch," he said.
In the first instance though, the new technique could reduce the number of lab mice that are killed because either males or females are required for certain medical experiments.
Dr James Turner, from the Francis Crick Institute in London, has identified 25,000 research papers published in the past five years, around 25,000 papers that required male- or female-only mice.
"The numbers of mice used in each case obviously varies," he said, "but the total mouse usage would easily be in the hundreds of thousands. This work could have immediate and valuable impact in scientific laboratories."
An independent report published earlier this week stated that animal welfare had to be at the heart of any relaxation of the rules that would allow gene editing on farm animals. One of the report authors, Peter Stevenson, who is the chief policy adviser for Compassion in World Farming, says, that he is "wary" of gene editing, generally, because it could be used to entrench the factory farming of livestock. but welcomed the possibility of its use to select the sex of chickens.
"We support its use to improve animal welfare, such as ensuring that hens only produce female chicks, as this would prevent the killing of millions of unwanted male chicks in the UK each year."
Barney Reed of the RSPCA said that the technology had to be regulated "robustly".
"This is especially pertinent when so many of the touted potential 'benefits' are for dealing with animal welfare or environmental problems created by humans ourselves."
Dr Ellis agrees. "Any potential use in agriculture, there would need to be extensive public conversation and debate, as well as changes to legislation.
"On the scientific side, there is also much work to be done over a number of years. Further research is needed, first to develop the particular gene editing toolkits for different species, and then to check they are safe and effective."
How it works
Whether a mammal is male or female is determined by the sex chromosomes. Females have a pair of X chromosomes - one inherited from the mother and the other from the father. Males, however, have one X chromosome from their mother and a Y chromosome from their father.
The researchers were able to prevent either XX or XY mouse embryos from developing by deactivating a gene, the result of which stopped embryos from progressing beyond a very early stage of around 16 to 32 cells.
They were able to select for sex by embedding one half of the gene editing molecule, called Crispr-Cas9, which deactivates the gene, into the mother's DNA and the other into the father's X or Y chromosome, depending on what sex was required.
The gene can only be deactivated if both parts of Crispr-Cas9 are brought together.
If the father's half of the gene editing molecule was on his Y chromosome, once it combines with the mother's DNA containing the other half of the editing molecule, the resulting XY male embryo would have both parts of the molecule that deactivates the gene, preventing further development. But all the female embryos, which did not inherit the molecule from the father, would develop normally.
For an all-male litter, half the Crispr-Cas9 is embedded into the father's X chromosome.
Follow Pallab on Twitter