David Cameron has warned that Nigel Farage presents a "threat" to the wellbeing of the British economy because the Ukip leader wants to "give up" on Britain's role as an outward trading nation.

In some of his harshest words about Ukip, the prime minister accused Farage of promoting a "totally unrealistic, pessimistic vision" which would make Britain turn its back on the world.

Cameron, who admitted that the Tories face a tough fight in the European elections on 22 May as opinion polls point to a Ukip victory, asked voters to support the "politics of the answer rather than the politics of anger".

The prime minister, who has been accused by Nick Clegg of failing to confront Ukip, also hailed Britain's EU membership for giving free access to European markets, although he insisted that it is right to carry out major reforms to the EU.

Speaking at a Q&A session at an engineering firm in Stroud, Gloucestershire, the prime minister said of the Ukip leader: "So, is he a threat to our economy? Yes he is because we are a trading nation and his answer is to give up."

Cameron said that Farage was wrong to try and pull Britain out of the EU which would limit access to crucial markets. "He is wrong. The idea of turning your back on the world and saying we are going to try and build fortress Britain, we are going to leave Europe, we are going to shut the door to anybody coming here. It is a totally unrealistic, pessimistic vision about what this country can achieve."

But the prime minister said that Labour and the Liberal Democrats were wrong to reject his plans to renegotiate the terms of Britain's EU membership ahead of a planned referendum in 2017. He said: "My message to anyone thinking about voting for Nigel Farage is don't give up on Britain in the world, give us a chance to get in there, negotiate a better deal for Britain and with me in charge you'll get a referendum before the end of 2017 where you can decide do we stay inside this reformed organisation or do we leave."

Cameron acknowledged that Ukip is a threat to the Tories on 22 May. Opinion polls are suggesting that Ukip will win the elections ahead of Labour in second place and the Tories in fourth. The prime minister asked: "Is he a threat to me and my party - well politics is about choice. We are in elections, they are competitive elections and I am going to try and get out around the country and convince people - don't give up, don't take a pessimistic view of Britain in the world."

But Cameron moved to reject an idea, suggested by some Tories, that he should bring forward the date of his planned EU referendum from 2017 if Farage fares well in the elections. "We shouldn't change the date because I want to offer the British people a better deal. The idea of a referendum now would really be offering people two unacceptable choices - stay in Europe, with everything as it is now, or leave altogether and give up on Britain's trading relationships. I don't want to give that choice because Britain should have a better choice so I will stick to the plan I have set out."

The prime minister did move to reach out to disaffected Tory voters tempted by Ukip when he said he understood that people feel frustrated. "I know people are frustrated with their politicians, sometime angry that we haven't taken more steps to deal with some of these issues. But what we have got to have in our country is the politics of the answer rather than the politics of anger because we have to fix these problems - fix our welfare system to it rewards the hard working, fix our immigration system so it benefits the whole of our country."