Royal Bank of Canada has agreed to buy the Canadian auto finance and deposit business of Ally Financial.

Canada's largest bank by market capitalization said Tuesday the purchase will strengthen its position as leader in the Canadian auto finance sector. The cost is about $1.4 billion.

Ally's Canadian unit provides financing to nearly 600 auto dealerships across Canada.

Ally is the new name for GMAC, formerly the lending division of General Motors. The lender required multiple bailouts after the financial crisis because of the auto industry's near-implosion and its heavy investments in mortgage bonds.

Ally has strengthened its direct banking franchise, advertising directly to consumers and offering low-cost, online-only accounts. But it remains primarily an auto finance company. The U.S. Treasury Department owns 74 percent of the larger Ally company.