David Cameron is prepared to override Britain's historic obligations under EU treaties and impose stringent border controls that would block Greek citizens from entering the United Kingdom, if Greece is forced out of the single currency.

The prime minister told MPs that ministers have examined legal powers that would allow Britain to deprive Greek citizens of their right to free movement across the EU, if the eurozone crisis leads to "stresses and strains".

In an appearance before senior MPs on the cross-party House of Commons liaison committee, the prime minister confirmed that ministers have drawn up contingency plans for "all sorts of different eventualities".

The worst-case scenario is understood to cover a Greek exit from the euro, which could trigger a near-collapse of the Greek economy and the flight of hundreds of thousands of its citizens who are currently entitled to settle in any EU country.

The prime minister said Britain is prepared to take measures to avoid a major influx of Greek citizens. "I would be prepared to do whatever it takes to keep our country safe, to keep our banking system strong, to keep our economy robust. At the end of the day, as prime minister, that is your first and foremost duty."

Asked by Keith Vaz, the Labour chairman of the House of Commons home affairs select committee, whether he would restrict the rights of Greek citizens to travel to Britain, the prime minister said he would be prepared to trigger such powers.

"I hope it wouldn't come to that," he said. "But, as I understand it, the legal powers are available if there are particular stresses and strains. You have to plan, you have to have contingencies, you have to be ready for anything – there is so much uncertainty in our world. But I hope those things don't become necessary."

Theresa May, the home secretary, confirmed last month that the government was examining contingency plans but indicated that she did not see any "increased movement". May told the Andrew Marr Show on BBC1 on 10 June: "So far ... we're not seeing any trends in any increased movements despite obviously the significant problems already economically in a number of eurozone countries. But I think it's right that as a government across the board, we look at the contingency arrangements that you know might be needed in these circumstances."

In his appearance before the committee, the prime minister also appeared to give the impression that he might abandon plans to publish the tax affairs of senior cabinet ministers. His remarks came after former Labour minister Margaret Hodge asked whether the government would publish details of so called "sweetheart" tax deals between the HMRC and large companies.

Cameron promised to write to Hodge after considering the matter. But he added: "The fact that we have taxpayer confidentiality is hugely important. Imagine the dangers of politicians fiddling around with each other's tax affairs. It just doesn't bear thinking about."

It is understood that the prime minister will publish limited tax details of a handful of senior cabinet ministers by the next general election in 2015. Cameron is understood to feel he has to follow the "Boris precedent" – the commitment by the London mayor in the recent election to publish his tax details – though it is expected that the prime minister will publish a redacted version of his tax return.