Citigroup, the largest U.S. bank by asset size, agreed to buy Mexico's second-largest bank company for $12.5 billion in stock and cash, the companies announced yesterday.

Analysts said the purchase of Grupo Financiero Banamex-Accival should strengthen Mexico's banking system.

The system is still struggling to recover from the devastating effects of the 1994-95 peso devaluation and loan crisis that led to a $100 billion government bailout of debt-heavy banks, analysts said. The crisis caused many Mexicans to lose confidence in their banks.

Banamex owns Banco Nacional de Mexico, which has assets of $37 billion, nearly 1,300 branches across Mexico and 27 percent of the country's deposits, more than any other bank.

Citibank has had a bank in Mexico for more than 70 years, but recently its presence in Mexico has grown more visible, with an increasing number of automated teller machines and branches opening, especially in Mexico City. Citigroup will merge the company with its current banking operations.

Robert E. Rubin, chairman of the executive committee of the board at Citigroup, said that while Citigroup has been active in Mexico for years, the Banamex deal will "catapult" Citigroup into a leadership position in Mexico's financial markets.

"Globalization is an undeniable reality, full of opportunities," Roberto Hernandez, president of the Banamex board of directors, said in a statement yesterday. "Our integration with Citigroup . . . assures that Mexico will have a strong bank that will continue competing effectively in a changing world scene."

The companies said they expect to complete the deal by the end of the year. Its completion would give foreign banks control of Mexico's two largest banks. Last year, Spanish giant BBVA took control of Bancomer to form BBVA-Bancomer, Mexico's largest bank, when ranked by assets.

Correspondent Kevin Sullivan in Mexico City contributed to this report.Banamex board President Roberto Hernandez, left, and Citigroup Chairman and CEO Sanford I. Weill expect to complete the deal by year's end.