EU finance ministers reached the deal after marathon talks in Brussels.