Ally Bank reached an agreement to sell a portfolio of agency mortgage servicing rights to Ocwen Financial Corp.

Ally (GMA) received interest in this portfolio from other financial institutions and said in January that Ocwen (OCN) and another company were "neck and neck" in a bidding war for the portfolio. 

However, Ocwen prevailed and the transaction is expected to close over the next few months. The deal is subject to approval by both Fannie Mae and Freddie Mac, according to Ally. 

The purchase price for the MSR asset is estimated at $585 million as of the end of January and the sale includes the transfer of the representation and warranty liabilities associated with the majority of the loans sold.

"Ally continues to make significant progress in exiting its non-strategic mortgage activities," said Barbara Yastine, president and chief executive officer of Ally Bank. 

She added, "Going forward, the bank's full focus and resources will be centered on its leading direct banking franchise and advancing its customer-centric deposit activities, as well as continuing to grow its key role in Ally's auto finance operation."

The deal is comprised of MSRs related to mortgage loans with an unpaid principal balance of $85 billion as of Jan. 31, 2013. Additionally, an estimated $5 billion of agency MSR was created on commitments made through the end of February.

Ally also has the right to sell Ocwen its remaining MSR portfolio in a seperate deal following this transaction.