The Publicis Groupe-owned agency has retained the £59m UK account and has added the business in Germany, Czech Republic and Slovakia.
ZenithOptimedia, which has handled the UK account since 2004, pitched against Mindshare, the incumbent on the business in Germany, in a final contest for the business.
A statement from Telefonica said: "ZenithOptimedia's footprint and capacity, with local teams in each of these countries, as well as the quality of its service, were decisive in the final assessment."
Sally Cowdry, O2's UK marketing director, said: "Over the past six years, we have been very pleased with the quality, creativity and value of ZenithOptimedia's media planning and buying for O2 UK. We are delighted that ZenithOptimedia has been awarded the European media business."
According to Nielsen, O2 spent £59m on UK media in 2009, including £22m on press and £12m on TV. It is also the UK's largest spender on digital media, committing £15.2m online.