Prime minister declines to answer whether he would align with Ukip as Nigel Farage also refuses to rule out deal

David Cameron and Nigel Farage have refused to rule out a deal between the Conservatives and Ukip after the election.

The prime minister was twice asked whether he would ever align with Ukip on the BBC1’s Andrew Marr Show, but dodged the question, saying he would not comment on any potential combinations before the election.

Cameron also suggested a Tory-led government could try to hold an early referendum on Britain’s membership of the European Union – a move that would satisfy the Eurosceptic right of the Conservatives and potentially smooth the path for a deal with Ukip.

The prime minister insisted, however, that his only focus at the moment was winning a Conservative-majority government: “I don’t want pacts or deals with anybody. I want a modern, compassionate Conservative party elected to run the government of this country.”

Cameron also avoided being rude about Ukip’s policies, as with Labour and the Liberal Democrats, simply saying some of the anti-EU party’s members held some “extraordinary” views and had said some “appalling things”.

“They have clearly got some issues but what I choose to focus on is the positive vision that I’ve got for the future of our country and the real choice,” he added.

With opinion polls and bookmakers suggesting a high chance of another hung parliament, all the parties will be thinking carefully over the next few months about the possibility of alliances with one or even two of their rivals.

Speaking on Sky’s Murnaghan programme, Farage also did not rule out some sort of deal with the Conservatives, while dismissing a pact with Labour or the Scottish National party. The Ukip leader, who has said he favours confidence and supply agreements over coalitions, made it clear his primary aim is a referendum on the EU as soon as possible.

Asked about working with Cameron, he said: “I think we’re jumping the gun a bit here. I don’t think anybody knows what’s going to happen in this general election. It’s the most open general election in decades so we are running a bit ahead of ourselves here.”

Pressed again on the question, Farage said: “I’m pretty clear I want my country back.

“I want us to be a self-governing nation. The big elephant in the room still is the fact that most of our legislation is not made in this country, it’s made somewhere else.

“I want our democracy back, I want control of our borders back. I want us to be able to negotiate our own deals on the world stage. To do all of that I need a referendum. We need a referendum.”

This is a change in tone from previous interviews, in which Farage has said he would not work with Cameron, who once called Ukip a bunch of “fruitcakes, loonies and closet racists”. At other times, however, Farage has said he would do a deal with the devil if it meant getting the UK out of the EU.

The prime minister said he would be “delighted” to bring forward a referendum if he manages to renegotiate the UK’s relationship with Brussels earlier than his promised timetable of the end of 2017. However, he also confirmed he would push for “proper, full-on treaty change”, which is likely to be time-consuming and difficult to achieve given that it requires getting an agreement with all other member states.

Cameron’s hint about an early referendum may, however, simply be a sign that he would want to get round rows within his party over Europe out of the way as soon as possible if he leads a new government.

Several cabinet ministers have signalled they would want to campaign to leave the European Union, but Cameron indicated on Sunday he would expect cabinet ministers to stick to the government position on Britain’s EU membership.

“There are Conservative members of parliament who want to leave the European Union come what may. But if you’re part of the government then clearly you’re part of the team that is aiming for the renegotiation referendum,” he said.

Tory sources rejected the idea of any connection between Cameron’s comments on an early referendum and the idea that this could pave the way for a political agreement with Ukip. They insisted Cameron had simply been sticking to his decision not to comment on hypothetical coalitions and there was no sign at all of a flirtation with Farage’s party.

The prime minister has left open the possibility of pushing for the UK to leave the EU if he does not get the changes he requires to improve Britain’s relationship with Brussels but he supports staying in a reformed EU if this can be achieved. He is holding talks with Angela Merkel when the German chancellor visits London this week and is likely to raise the prospect of reducing EU immigration by clamping down on benefits for migrants.

Pat McFadden, Labour’s shadow minister for Europe, said it was extraordinary that Cameron would not say how he planned to vote in his own referendum.