British expatriates could be banned from claiming tax credits for up to four years as part of a compromise deal David Cameron is negotiating with fellow EU leaders, the Guardian understands.

In an attempt to win support for his proposal to ban EU migrants from claiming in-work benefits for four years, the prime minister is looking at whether the ban could apply to Britons who live abroad for four years or more.

The plan could prove controversial among British workers who take advantage of EU free movement rules to relocate to countries such as Spain, and who would expect to be able to top up low wages through tax credits on their return to Britain.

Downing Street appears to be ready to risk a row with such expatriates as the price for brokering a compromise with fellow EU leaders on Cameron’s welfare proposals, which are the most difficult part of his EU renegotiation.

The prime minister looks to be reaching out to fellow EU leaders by signalling that the four-year ban on in-work benefits would only apply to new arrivals to the UK from other EU countries. This means that about a million migrant workers from the Visegrad group of countries – Poland, Hungary, Czech Republic and Slovakia – working in the UK would be free to continue claiming tax credits without any restrictions.

Cameron is telling EU leaders that he wants to deal with the “artificial draw” of the UK’s non-contributory welfare system in attracting migrants. This does not apply to EU migrants who have already settled in the UK.

The strength of feeling about the proposed ban was highlighted in Budapest on Thursday when the prime minister’s Hungarian counterpart, Viktor Orbán, told him to alter the plan or risk portraying EU workers as parasites. Orbán said he was confident the Visegrad group would reach an agreement with Cameron on his welfare reforms. But the Hungarian prime minister said the reforms must not discriminate against citizens from the Visegrad countries and other EU member states who are entitled to claim tax credits in the UK.

The easiest way to avoid charges of discrimination would be for the four-year ban on in-work benefits to also apply to British citizens. But a proposal discussed in Downing Street a few months ago, which would have applied the ban to British citizens aged 18-22, has been shelved for the moment.

The prime minister is telling EU citizens that imposing the restriction on UK citizens of this age would undermine a key incentive that encourages young people into work. The chancellor is a strong critic of tax credits, which will eventually be replaced by universal credit. For the moment, and before the “national living wage” reaches £9 an hour in 2020, ministers acknowledge the importance of tax credits.

But Cameron is prepared to go some way to evading the discrimination charge by applying the ban to UK citizens who have lived abroad for more than four years. British officials say ideas for a possible compromise are not fixed.

The sign of movement in the negotiations came amid a growing sense that Downing Street believes Cameron is on course to secure a deal with EU leaders that will allow him to recommend a yes vote in the upcoming referendum. However, he may have to wait until March to reach an agreement.

Philip Hammond, the foreign secretary, who has previously floated the idea of voting to leave the EU in the event of a breakdown in the negotiations, said he could not anticipate voting no if Cameron secured a deal. He told BBC Radio 4’s Today programme: “I can’t envisage us negotiating a deal which the prime minister thinks is good enough to recommend to the British people and which I feel I want to campaign against. I can’t envisage that circumstance.”