European leaders have moved to halt the crisis engulfing Spain and Italy by agreeing a radical bailout package for the single currency's teetering banks.

Amid deep divisions over the debt and currency crisis, and under immense pressure to come up with credible moves, Angela Merkel, the German chancellor, softened her hard line on fiscal discipline and debt repayment to hand Mariano Rajoy, the Spanish prime minister, a summit triumph.

Leaders agreed to set up a supervisory system for eurozone banks that will form the first step towards full banking union, scrapped the requirement that governments get preferential status over private investors in the event of a default and eased the stiff terms for future bailouts.

Markets surged after the deal was agreed, giving European leaders the respite they have been seeking for several months. The German and French stock markets jumped more than 4% while the main market in New York soared in early trading as renewed confidence among investors erased several weeks of losses.

In Madrid and Rome, the deal was hailed as a victory over the all-important bond markets, which have crippled both governments with sky-high interest rates. The interest rate on Spain's 10-year bonds fell the most since August to 6.3% after hitting 7% in recent weeks, a level analysts believe is unaffordable.

There was also relief for prime minister Mario Monti of Italy, below, who spoke of "double satisfaction" following the defeat of Germany in the Euro 2012 football contest.

A two-day summit ran on through Thursday night as brinkmanship from Rome and Madrid pitched the meeting to the brink of collapse. It concluded with some of the more far-reaching political decisions to emerge from 30 months of crisis in the single currency.

Divisions remain, however, and working out the detail and implementation of a "banking union" – a first step towards establishing a eurozone federation – will be protracted. The most immediate decisions concerned Spain and its attempts to contain a crisis sparked by bad banks.

Merkel's main concession was to agree to waive so-called preferred creditor status on the mooted €100bn eurozone rescue programme for the banks. This is to take place within weeks, meaning that private investors will not play second fiddle to the eurozone bailout fund if the debt has to be rescheduled. In effect, eurozone taxpayers are at as much risk as private creditors in the Spanish bank bailout, a politically sensitive concession for the German leader. The other big decision was to change the eurozone bailout rules to enable direct recapitalisation of banks without the money going via governments and adding to national debt levels.

This can only take place once the new bank supervisory system is up and running – that could take two years – but at that point the Spanish government would be allowed to erase the borrowing from its books. "I'm quite pleased with the outcome," said Mario Draghi, the president of the European Central Bank, who has been a fierce critic of political leaders' failure to get to grips with the crisis. He confirmed the new supervisory powers would be vested in the ECB.

While Rajoy emerged as the main beneficiary of the summit, Monti also claimed success from a vaguely worded decision enabling the eurozone bailout funds to buy up government bonds, a move he hopes will reduce the cost of Italy's borrowing. While the statement said that the funds could be used more "flexibly", Draghi and Merkel emphasised continuing "conditionality" or strict terms for any country seeking help.

President François Hollande of France mentioned Italy as a possible beneficiary and said: "We agreed to fully use [these] tools without additional requirements from these countries."

Monti and Rajoy ambushed the summit on Thursday evening, blocking any progress on an overall deal until they were guaranteed specific decisions aimed at bringing down their soaring borrowing costs. That meant that the 17 leaders of the eurozone held their own summit for several hours until four in the morning and hammered out the accord.

Tempers were frayed. North European diplomats spoke of brinksmanship from Monti. "Because of the crazy demands of Spain and Italy, the end result is not satisfactory," said one.

With acute divisions remaining, there will be plenty of argument in the months ahead. "They will be quite difficult negotiations because we are in a new area," said Merkel. The Germans want the new banking regime to cover only the eurozone's "systemic banks," but Hollande said all eurozone banks should be included. "If any are left out, then we will be back to the Spanish situation."

And while the German parliament moved to pass Merkel's new euro rulebook, the fiscal pact, Hollande tied ratification in France to several other elements on the eurozone fiscal and economic agenda and a much slower schedule. Despite the concessions from Germany, Merkel also emphasised that she retained the power to block too liberal a use of the bailout funds. Banks could only be recapitalised directly once the new supervisory system was in place "in the medium-term" and she would be able to veto any such decisions. The decision to waive the preferential treatment for the bailout fund on the Spanish rescue was a one-off that would not be repeated in any further programmes, Merkel said.