Sprint Corp. and T-Mobile US Inc. have agreed on new terms for their merger, as the wireless carriers race to close the deal after overcoming a federal court challenge.

The parties will improve the exchange ratio in the all-stock deal for T-Mobile’s parent, Deutsche Telekom AG, the companies said in a written statement confirming an earlier Wall Street Journal report.

U.S....