UK taxpayers' money will be protected in any Greek bailout under a legally binding agreement struck with the European Commission and the majority of other EU members.

The agreement will not only cover any funds going towards the Greek bailout but also to any other future Eurozone rescue packages, says Chancellor George Osborne.

Other non-Eurozone countries like Denmark and the Czech Republic will also be protected, the Treasury said.

The decision on protecting non-Eurozone countries' funds to bailout Eurozone countries came after European Commission President Jean Claude Juncker said EU finance ministers had agreed to use the European Financial Stability Mechanism for a €7bn bridging loan to Greece until the country works out the terms of its bailout.

Many countries, including the UK, had objected to the use of the fund to help Greece.

The mechanism is an emergency fund set up to support any of the 28 member states in financial difficulty.

A Treasury spokesman said the EU law would be changed so that a cash fund, held by the European Central Bank would cover any liabilities that would have fallen to the UK or other non-Eurozone countries.

The deal established the principle of different rules for those outside the Eurozone, the Treasury spokesman said.

"We have today secured a significant victory and strengthened the protections for the UK in the latest Greek bailout and any future bailouts of Eurozone countries. I made clear to my European counterparts that this was an absolute red line for Britain," Osborne said.

"These have been tough talks, but the agreement announced this evening means an impregnable ring fence around British taxpayers' money, which will not be at risk in any way in this emergency financing for Greece."

He expects the principle of treating non-Eurozone countries differently to be "acknowledged" when the UK re-negotiates its relationship with the EU ahead of the referendum on its membership in the group.

"This agreement establishes an important principle in EU law: that the responsibilities of the euro zone countries and those members of the EU, like Britain, who are not part of the single currency and do not want to be, are very different," Osborne said, according to Reuters.

More about Greece's debt crisis