Leaving the European Union would be an act of "economic self-harm," British Prime Minister David Cameron said during a televised grilling that saw him challenged on the emotive topic of immigration and accused of scaremongering about the impact of quitting the 28-nation bloc.

Three weeks before British voters decide whether to stay in the EU, Cameron on Thursday was pressed on the repercussions for immigration, security and the economy as he fielded questions from a journalist and audience members during a lively Sky News program.

Cameron's Conservative government says it aims to reduce net annual migration to less than 100,000 — but last year it was more than 330,000, roughly half of it from other EU nations.

He insisted that Britain can use curbs to welfare benefits and other measures to control migrant numbers while remaining in the bloc, even though citizens of all EU nations have the right to live and work in other member states.

"There are good ways of controlling migration and there are bad ways," Cameron said.

"It would be madness to try to do that by trashing our economy and pulling out of the single market."

The referendum campaign is growing increasingly heated as widely varying polls suggest an unpredictable result. The "leave" side is stressing the pressure that EU immigrants have put on British jobs and public services, while "remain" campaigners seek to keep the focus on the economic uncertainty that U.K. exit — known as "Brexit" — would wreak.

Many voters have expressed frustration at all the claims and counterclaims, and Thursday's studio audience — selected to include pro-and anti-EU voters, as well as undecideds — was sometimes vocally skeptical of Cameron. One young woman accused the prime minister of "waffling" in response to her question about whether Turkey would join the bloc.

Cameron said leaving the EU's single market of 500 million people — with which Britain does almost half its trade — would hurt the British economy, and negotiating new trade deals could take a decade.

He said tumbling out of the single market "would be an act of economic self-harm," and rebuffed claims that he was scaremongering.

"I am genuinely worried about what would happen if we leave," he said.

Cameron also denied using hyperbole when he claimed last month that a Brexit would increase the risk of European war.

"On our continent in the last century, twice we had an enormous bloodbath between our nations," he said. "Can we be so confident that we have solved all of Europe's problems and all of Europe's tensions?"

The Vote Leave campaign said the audience's skepticism "showed the public doesn't trust Cameron."

"All he had was a single bogus argument — that we have to be in the EU to trade with Europe, which is simply untrue," chief executive Matthew Elliott said.

Other members of the EU are also weighing in as referendum day looms, with a mix of entreaties to stay and warnings of the risk of a Brexit.

German Chancellor Angela Merkel said Thursday that Britain would get better results from the EU "when you sit at the bargaining table," rather than if it were lobbying from outside.

Cameron conceded that he often found dealings with the EU frustrating.

"Sometimes this organization drives me crazy," he said. "But do I sit there thinking Britain would be better off if we left? Are we quitters? ... Absolutely not."