The deal cost €5 billion in cash and a 17.6-percent stake in Telefonica Deutschland.
The sale of E-Plus by Dutch telecom operator KPN should enable it to pay a share dividend in 2014 despite its heavy debts.
Assuming it receives approval from competition authorities, the sale should allow for €5.5 billion in efficiencies on the German mobile communications market, KPN said in a statement.
"KPN will use most of this money to increase its financial flexibility and intends to resume payments of dividends to stockholders for 2014," the company said.
"KPN has been trying to sell for years and Telefoncia was a natural buyer," said Nico van Geest of Keijser Capital, noting that the Spanish operator wanted to invest less in recession-hit southern European economies.
"They want to be more in the north, in England, Germany," Van Geest told AFP.
KPN had been urgently looking to sell its German business as a way to raise cash, but had struggled to do so given a poor investment climate.
KPN was in 2012 the target of a hostile takeover effort by Mexico's America Movil, owned by tycoon Carlos Slim, which owns 27 percent of KPN, making it the largest shareholder.
Analyst Van Geest said the sale of such a big foreign asset was however "dramatic" for KPN, which is now "becoming a local player."
"They had an international flavour because of being in other countries, but now it's becoming a local player, it's really not taking part in this game anymore," he said.
The announcement comes as KPN announced a 68-percent fall in net profit for the second quarter of 2013 to €108 million. Sales in the period were off 8.1 percent from the figure a year earlier to €2.93 billion, the company said.
"Conditions remained challenging in the first half of 2013, however we have further strengthened our market positions," chief executive Eelco Blok said.