(L-R) European Central Bank President Mario Draghi, Spanish Finance Minister Luis De Guindos and French minister for Economy, Finances and Foreign Trade attend a Eurozone meeting on July 9, 2012 at the EU headquarters in Brussels.

Eurozone ministers agreed to bail out Spain at talks ending Tuesday, with a first tranche of 30 billion euros ($37 billion) to be offered to relieve its banking sector by the end of the month.

Jean-Claude Juncker, who heads the eurozone finance ministers group, said after nine hours of talks on Monday ended beyond midnight, that the group reached political agreement on a draft memorandum of understanding on Spain and were "aiming at reaching a formal agreement in the second half of July."

The accord "will enable a payment of 30 billion euros by the end of the month" to help Spain's distressed banks, he said, with reimbursement deadlines set "up to 15 years."

The ministers also agreed to extend a 2013 deadline for Spain to cut its public deficit to the EU 3.0 percent limit by one year, he said.

Juncker told a press conference that the deadline was extended in view of the difficult economic conditions Spain faced but the country now had to implement all the measures needed to bring its public finances into line with EU norms.

In exchange for the loans, the eurozone will demand reforms of specific banks as well as the banking sector as a whole, said the EU's Economic Affairs Commissioner Olli Rehn.

Spain would also have to abide by EU ceilings on deficits, trimming its huge deficit to 6.3 percent of gross domestic product this year, 4.5 percent in 2013 and 2.8 percent in 2014, Rehn added.

Spain in May revised its 2011 public deficit -- the shortfall between government revenues and spending, saying that it stood at 8.9 percent of gross domestic product instead of 8.51 percent as reported earlier.

The same month, the EU warned that Spain would miss its public deficit targets this year and next while remaining in recession through 2013.

The conservative government of Prime Minister Mariano Rajoy has pledged to cut Spain's public deficit to 5.3 percent this year.