Farmers have a lost a High Court bid to overturn a government decision not to introduce badger culling in Derbyshire to control bovine TB.
National Farmers' Union (NFU) lawyers told a judge a "direction", made in September 2019, was "irrational".
They added the real reason for the decision was because the prime minister took a "personal interest".
Mrs Justice Andrews, who analysed arguments at a hearing on Skype in April, has dismissed the NFU challenge.
The cull was set to go ahead in Derbyshire last winter in a bid to control bovine TB.
But in September the government said it would not grant the county's farmers licenses to do it.
NFU lawyers told Mrs Justice Andrews lobbying by Badger Trust chief executive Dominic Dyer included meeting Mr Johnson's partner, Carrie Symonds, in Downing Street.
Sir James Eadie QC, from Environment Secretary George Eustice's legal team, said the idea that there was "something sinister" about Mr Johnson's involvement was "unsustainable".
Farmers believe culling is necessary to control the disease that affects the beef and dairy industries, but opponents say it is inhumane and ineffective.
In March, the government announced it would be phasing out culling in favour of vaccinations.
Mrs Justice Andrews said, in a written ruling published on Wednesday, it was a "difficult" decision which involved the "exercise of complex political and ethical value judgments".
She added the direction made against culling was not irrational.
"In short, however compelling the case for permitting the licence to be issued might appear, there were countervailing political considerations which legitimately led the responsible decision-maker to conclude that no licence should be granted in Derbyshire for that year," she said.
A spokesman for the Department for Environment, Food and Rural Affairs said it welcomed the ruling.
He said: "The government remains committed to its strategy to combat bovine TB which leads to the slaughter of over 30,000 cattle every year and considerable trauma for farmers."