Under the accord Athens will receive co-ordinated bilateral loans from its eurozone partners as well as International Monetary Fund (IMF) assistance if it is unable to raise enough money from commercial markets.
George Papandreou, Greece's prime minister, hailed the deal as "very satisfactory" and said that Europe had taken "a step forward".
Alan Fisher, Al Jazeera's correspondent in Brussels, explained that no aid was being given to Greece yet as Athens wants to go to the markets to see if it can refinance its debts on its own.
Greece has struggled with the markets which have demanded very high interest rates because until the deal was announced Greece appeared to have no other lenders to turn to.
The deal gives Greece a "Plan B", removing the risk of default, reassuring credit markets and thereby reducing the interest it needs to pay on any refinancing plan and averting the need for it to request aid.
The cost of insuring Greek debt fell on news of the agreement, and the premium investors charge for holding Greek bonds rather than benchmark German bunds narrowed.
But it remained more than double the spread charged on fellow eurozone weaklings Ireland and Portugal, and four times that of Spain.
Papandreou said his country would press ahead with painful austerity measures to slash its huge budget deficit, measures that have prompted widespread strikes and protests in Greece.
No numbers were given of the eurozone deal but a senior European Commission source said the support package would be worth 20-22 billion euros ($27-29bn) if it was required.
Greece needs to borrow around $21.4bn between April 20 and May 23 to refinance maturing debt.
Tough terms imposed by Angela Merkel, the German chancellor, mean the mechanism may be activated only under strict conditions and would require the unanimous approval of the eurozone, giving Berlin a veto.
The plan will not involve direct loans from the EU – something Merkel strongly objected to – but bilateral loans from individual eurozone countries instead, and at market rates.
Merkel has also repeatedly warned that the safety net is only to be used as a last resort.
|Merkel has repeatedly warned that the safety net is only to be used as a last resort [AFP]
"This mechanism, complementing International Monetary Fund financing, has to be considered ultima ratio [last resort], meaning in particular that market financing is insufficient," the agreement said.
Without a fallback mechanism, EU leaders had feared that Greece's debt-servicing problems could spread to other countries in the eurozone, including Portugal, Spain and Italy.
At Berlin's insistence, eurozone leaders also called for proposals by the end of the year to tighten the bloc's battered budget discipline rules, which failed to prevent Greece running up giant deficits and public debt.
Under the deal for Greece, eurozone countries would provide the majority of any funding on rigorous conditions recommended by the European Commission and the European Central Bank (ECB).
The IMF would contribute one-third of the money and its expertise if needed.
Many details remained unclear, such as the division of responsibilities between the IMF and the eurozone in a rescue.
Wrangling over the Greek issue has threatened cohesion across the eurozone and driven down the value of the euro.
Some eurozone states, notably France, and ECB policymakers, had previously opposed IMF involvement, arguing that such a move could be seen as an indication that the eurozone could not solve the deepest crisis in its 11-year existence on its own.
"If the IMF or some other body exercises the responsibility in lieu of the Eurogroup or instead of governments, it is evidently very, very bad," Jean-Claude Trichet, the ECB president, told France's Public Senat television in an interview.
The euro fell to a 10-month low against the dollar as investors took that initial view.