By Jonathan D. Rockoff

Illumina Inc., a leading maker of the machines that sequence genes, said Monday it will pay $7.1 billion in cash and stock for a developer of a long-sought blood test that promises to detect cancer early.

The deal for the part of Grail Inc. that Illumina doesn't already own will move the company deeper into the application of its gene-sequencing technology to the diagnosis and treatment of patients, a potential multibillion-dollar market.

Illumina founded Grail four years ago and owns a large stake in the company. Under the terms of the agreement, Grail owners excluding Illumina will get $3.1 billion in cash and shares in the gene-sequencer maker valued at the remaining $4 billion, Illumina said.

The owners will also have the option to receive additional cash or stock, or get contingent value rights to a portion of Grail's annual revenue for the next 12 years, Illumina said.

Owners who choose to get the rights will get about 2.2% of Grail's first $1 billion in revenue each year and roughly 7.9% of any Grail-related revenue above $1 billion, Illumina said.

The Wall Street Journal earlier reported that Illumina had agreed to buy Grail. Last week, Bloomberg reported Illumina was nearing a deal for Grail. The agreement comes as Grail was laying the groundwork to go public.

The purchase will be Illumina's biggest acquisition and propel it further into the clinical applications of its gene sequencers and related products and services, which have rung up $1.3 billion of the company's $1.5 billion in total revenue during the first half of this year.

Over the past several years, San Diego-based Illumina has been seeking a larger position in the faster-growing genomic-application market.

"We believe early detection of cancer could be one of the largest applications of genomics over the next 15 years," Illumina Inc. Chief Executive Francis deSouza said in an interview.

By 2035, early-detection testing could account for $46 billion of the $75 billion world-wide market for cancer genetic sequencing, which is growing at a compounded annual rate of 27%, according to Illumina.

For entry into that market, Illumina is paying up for a company that doesn't have any revenue. The deal's success will depend on Illumina successfully launching Grail's cancer-detection blood test and persuading health insurers to pay for it.

Illumina has a small genomic-application business, selling molecular tests that help doctors diagnose genetic diseases and pick cancer therapies. In 2013, Illumina bought the company Verinata Health and its test that looks in the blood of pregnant women for fetal chromosomal disorders like Down syndrome.

Grail grew out of Illumina's discovery of signs of cancers in the maternal blood samples.

Ever since, the Menlo Park, Calif., company has been on the front lines of efforts by a number of companies seeking to build a blood test that detects tumors in patients even before they show symptoms. Such tests are often referred to as "liquid biopsies."

Identifying cancer so quickly has been a long-sought but elusive goal of doctors and researchers because it promises the opportunity for earlier and more effective treatment.

The research has proven challenging. The tests need to look for a range of molecular cancer markers if they were going to identify a variety of different tumors. To avoid false positives, the tests also need to distinguish between mutated DNA shed by tumors and by other cells.

Grail has been planning to launch its test, called Galleri, next year. Studies found it could detect more than 50 different cancers, and it generated false positives less than 1% of the time, according to the company. Studies also found the test often identified the cancer type.

The test is expected to appeal to patients and doctors, but analysts have said its commercial potential will depend on gaining reimbursement. Grail has been planning to target the test initially for sale to buyers such as concierge-medicine practices and self-insured employers.

Grail's test may be the first liquid biopsy that detects cancer early to go on sale, Mr. deSouza said. Grail is "getting ready to launch the product in 2021, and we feel we can accelerate their plans," including to expand its sale to health insurers, he said.

Illumina said it expects to close the deal in the second half of 2021.

Write to Jonathan D. Rockoff at Jonathan.Rockoff@wsj.com

Corrections & Amplifications

This was corrected at 8:43 a.m. ET because the original incorrectly said Francis deSouza was CEO of Grail. Francis deSouza is chief executive of Illumina Inc.