Intercontinental Exchange Inc., parent company of the New York Stock Exchange, agreed to buy mortgage-data firm Black Knight Inc. in a cash-and-stock deal valued at $13.1 billion, stepping up its involvement in the U.S. mortgage market.

The exchange operator, known as ICE for short and Black Knight confirmed the deal in a joint press release on Wednesday. The release came after Bloomberg reported earlier in the afternoon that ICE was considering a deal to acquire Black Knight.

The deal has been approved by the boards of both companies, and is expected to close in the first half of next year, subject to regulatory approval and other customary closing conditions, the companies said.

Shares of Black Knight rallied 14.5% after the news, while ICE shares dropped 4%.

Atlanta-based ICE is best known as an operator of exchanges, clearinghouses and other financial-market infrastructure.

In recent years, it has pivoted into housing in a bet on the growing digitization of the mortgage market.

In 2020, ICE agreed to buy mortgage-software firm Ellie Mae for about $11 billion. Earlier, the exchange company bought Simplifile, a firm that facilitates electronic processing of mortgage records, and the parent company of Mortgage Electronic Registrations Systems, a national electronic registry for tracking servicing rights and ownership interests for U.S. mortgage loans.

Black Knight, based in Jacksonville, Fla., creates software, data and analytics for the real-estate and housing-finance markets.

Write to Alexander Osipovich at alexander.osipovich@dowjones.com