Dialysis provider DaVita Inc. couldn’t operate its large network of physician clinics profitably, but Minnetonka insurance giant UnitedHealth Group is betting nearly $5 billion that it can.

The two health care companies announced Wednesday that UnitedHealth has agreed to acquire DaVita Medical Group in a $4.9 billion all-cash deal set to close in 2018, pending regulatory approvals. The medical staff of more than 2,000 at DaVita Medical would join a roster of some 30,000 doctors already working for or affiliated with UnitedHealth’s health services business, Optum.

“This acquisition fits right into UNH’s [UnitedHealth Group’s] plan to direct patients from high-cost hospital settings to lower-cost urgent care and outpatient facilities and will leverage its vast physician footprint to accelerate that change,” Raymond James analyst Michael J. Baker wrote Tuesday in a note to investors.

Word of the deal comes just days after UnitedHealth competitor Aetna agreed to be acquired by CVS Health in a $69 billion bid to vastly expand in-store health care service offerings.

Reuters reported last month that DaVita was looking to sell its medical division for up to $4 billion, after it had become what the news agency called “a significant drag” on the overall business.

DaVita Medical Group posted a $5 million operating loss on nearly $1.2 billion in net revenue in the third quarter, excluding a $600 million goodwill impairment charge, according to securities filings.

Jeffrey Loo, an industry analyst with the investment research firm CFRA, wrote Wednesday that the acquisition of DaVita’s clinics, urgent-care centers and surgery centers should mesh well with Optum’s focus on primary care, urgent care and outpatient care businesses.

“This unit posted a Q3 loss for DVA [DaVita]. We think UNH’s leverage and overlap in certain areas, including cost synergies, should improve the unit’s profitability,” Loo wrote.

DaVita Medical Group serves about 1.7 million patients per year in nearly 300 clinics with primary and specialty care. It also operates 35 urgent-care centers and six outpatient surgery centers.

“The physicians and clinicians of DaVita Medical Group provide outstanding patient care, and we look forward to supporting their continued success in serving their patients and communities,” said Andrew Hayek, chief executive of an Optum division called OptumHealth. “We also look forward to working closely with the leadership team of DaVita Medical Group to combine our capabilities and, supported by the data analytics and technology capabilities of Optum, enhancing patient care and the value we provide to the communities we serve.”

As UnitedHealth looks to make DaVita Medical Group profitable, CVS Health’s proposed acquisition of Aetna rolled out earlier this week is aimed at expanding “health hubs” in CVS stores.

Both deals reflect the continued blurring of lines between health insurers and providers.

UnitedHealth’s Optum business already has the ability to provide care directly to patients through its Surgical Care Affiliates network of surgical centers, its MedExpress network of urgent-care centers, and its HouseCalls program to provide annual visits to patients at home.

Shares of DaVita Inc. rose nearly 14 percent to $69.20 on Wednesday. The company said it will focus on its kidney care business, which generated $2.3 billion in operating revenue in the most recent quarter, as well as invest in other health care services. UnitedHealth Group shares closed at $219.94 Wednesday, virtually unchanged.