As attorneys for Apple Inc. and Qualcomm Inc. finished opening statements Tuesday for their multibillion trial in San Diego, the two companies signed a settlement agreement.

According to a statement released by Qualcomm at 12 p.m., Apple and Qualcomm will end all litigation between the two companies, as well as Apple’s contract manufacturers: Foxconn, Pegatron, Wistron and Compal. The settlement marks the end of a costly, two-year legal battle for the companies.

"This is certainly a rarity," U.S. District Judge Gonzalo Curiel said after he dismissed the jury on Tuesday.

“In our remarkable legal system, we encourage parties to settle disputes amicably when they can,” Curiel said.

Apple and Qualcomm had sued each other for breach of contract, with Apple saying Qualcomm owed it roughly $1 billion in payments per an agreement between the two companies, and with Qualcomm claiming more than $7 billion in unpaid royalties. The companies had launched roughly 80 cases against each other around the world. Now, all of that may be coming to an end.

Qualcomm said the settlement includes a payment of an undisclosed amount from Apple to Qualcomm.

The companies also reached a six-year licensing agreement, effective April 1, 2019. Instead of licensing through contract manufacturers, Apple will now license Qualcomm's technology directly. The agreement includes a two-year option to extend, and a multiyear chipset agreement.

While neither company commented on the timing of the settlement, there were a couple of factors in play that may have encouraged them to iron out a deal. For Qualcomm, the ability to once again collect licensing revenues from Apple would certainly be a strong motivator, and for Apple, the ability to release 5G handsets appears to have been at stake.

Hours after the two companies announced a settlement, Intel Corp. suddenly announced it would exit the 5G smartphone modem business. Apple had turned to Intel to supply modem chips for its newer phones in late 2016, around the same time its legal dispute with Qualcomm began. With the new contract in place, it seems likely that Qualcomm could serve as the supplier for Apple's 5G phones.

Qualcomm's stock jumped more than 20 percent on the news, to $69.50 as of 12:30 p.m. Pacific Time.