But there is a long and awkward way to go. While the government has set targets, it has little control over the variables. In the year ended March 2014, the government reports, 265,000 non-European Union citizens moved to Britain, ending a steady decline since the recent peak of 334,000 in 2011. Net immigration to Britain from the European Union rose to 130,000 in the year through March, up from 75,000 two years ago.

Total net immigration in the year through March was 243,000. That is back up to the 10-year average of nearly a quarter of a million people, said Andrew Green, chairman of Migration Watch U.K., which advocates restrictions. “If allowed to continue,” he said, the population will increase by 12 million — two more Scotlands — in 20 years. “That’s huge,” he said, arguing that three-quarters of British voters “want to see it reduced.”

So immigration is a fertile topic for the right and for the nationalist U.K. Independence Party, which is squeezing Mr. Cameron, and it is so sensitive with voters that even the opposition Labour Party has little to say about it.

Thursday’s two by-elections were a warning shot for both parties. UKIP won the seat in Clacton-on-Sea by a large margin, as expected, after the legislator Douglas Carswell defected from the Tories to join Nigel Farage and UKIP. That was historic, because Mr. Carswell became UKIP’s first elected member of Parliament. But what really shook the ground was the by-election in Heywood and Middleton, near Manchester, when the UKIP candidate came within 617 votes of defeating the heavily favored Labour candidate in the Labour Party’s heartland.

By-elections are famous for protest votes that don’t usually carry over to the general election. But UKIP, an essentially English nationalist party, is making headway against both main parties on the issues of sharply reducing immigration and quitting the European Union. Britain is an attractive place to live and find work, said Jonathan Portes, director of the National Institute of Economic and Social Research. Not only that, as a colleague, Heather Rolfe, points out, Britain benefits in the long run from immigrants, who provide flexibility for employers and pay more in taxes than they take from public funds.