ZenithOptimedia already handles the £41 million TV and print buying account, which it has held since 2004. It will add the online duties from April.
Media Republic has held the online planning and buying since 2002. Agency Republic, which is owned by Omnicom, will continue to handle online creative for the account. Last year, it created O2's "favourite place" Facebook campaign, which became the UK's most successful branded social network community.
In a statement, O2 said the change would "improve media commercial structures, which promises significant efficiencies".
Sally Cowdry, the O2 UK marketing director, said: "We've been taking stock over a long period, and there has been a blurring between off- and online media, especially from a customer point of view. So our media will be much more efficient and effective if it is bought together."