UBS agreed to buy Credit Suisse as part of a cut-price deal designed to alleviate panic in the banking sector.