ATHENS--Greece's Piraeus Bank SA (TPEIR.AT) has agreed to purchase the Greek unit of Portuguese lender Banco Comercial Portugues SA (BCP.LB, BPCGY) in a deal that will provide the local lender with a capital boost and help prevent the Greek government from taking complete control of its management.

Before selling the Millennium Bank unit, BCP will recapitalize it with 400 million euros ($521 million), including EUR139 million already injected into the bank, the two companies said in separate statements Monday.

The investment will help Piraeus meet a 10% threshold needed to keep control of management, amounting to some EUR530 million, as it turns to the state for aid after being hit with steep losses from Greece's debt restructuring and rising nonperforming loans.

"The acquisition of Millennium further strengthens our capital position and earning-generation capability, while the BCP investment into Piraeus Bank brings us over the minimum 10% threshold private-sector participation in the upcoming recapitalization, which is a prerequisite for the bank to maintain its private character," said Michalis Sallas, chairman of Piraeus Bank.

"We are confident that we can achieve an even-higher participation of private investors, in this landmark rights issue of Piraeus Bank," he said.

It is the first time that a Greek lender has said it will be able to raise the money as it seeks capital in turn, sending Piraeus Bank shares more than 17% higher on the Athens bourse in late trade. The Greek banking-stocks index was up 21% on hopes that other lenders will be able to follow suit and keep control of management. In Lisbon, BCP shares raced ahead 4.2% late Monday, with investors cheered by news of the deal. BCP's Greek unit has long been a drag on the results of the Portuguese bank, which is also struggling with a recession at home.

As part of Greece's latest EUR173 billion bailout by its euro-zone peers and the International Monetary Fund, EUR50 billion has been set aside to recapitalize the country's four big banks, which control more than four-fifths of the Greek banking market.

The ambitious bank-recapitalization plan, already months behind schedule, is meant to restore the banks to health after they were wiped out by the country's EUR200 billion debt restructuring last year. Under terms of the plan, the banks must secure 10% of their capital needs from the private sector to maintain management autonomy and retain their private character.

Greece's bank-rescue fund, the Hellenic Financial Stability Fund, will underwrite the balance--but will have only restricted management rights if its share in a bank is less than 90%.

In the process, Greece's banking sector has been going through a rapid consolidation, with the four top banks--National Bank of Greece SA (NBG, ETE.AT), Eurobank Ergasias AS (EUROB.AT, EGFEY), Alpha Bank AS (ALPHA.AT, ALBKY) and Piraeus Bank--hoping that, by bulking up, they will be able to attract private capital for the recapitalization. Piraeus has already expanded by acquiring the Greek units of Societe Generale SA (GLE.FR) and the healthy assets of state-owned farm lender ATEBank SA (ATE.AT).

The Portuguese bank, which last year received government help to improve its capital ratios, has been losing money in Greece due to the country's ongoing economic problems. With the transaction, BCP will also lower its risk-weighted assets by about EUR4 billion, in turn raising its capital ratios. At December, the bank's core tier 1 ratio was 9.8%.

Under the rights-issue agreement, BCP has committed that it won't sell its shares in Piraeus for six months.

Write to Stelios Bouras at stelios.bouras@dowjones.com and Patricia Kowsmann at patricia.kowsmann@dowjones.com.

Subscribe to WSJ: http://online.wsj.com?mod=djnwires