Merck & Co., the second-biggest U.S. drugmaker, agreed to buy Idenix Pharmaceuticals Inc. for about $3.85 billion to expand its experimental pipeline for hepatitis C treatments.

Buying the Cambridge, Massachusetts-based company will help Merck in the competition to develop a daily, all-oral regimen that treats different strains of the viral infection and doesn’t include ribavirin, a standard therapy for hepatitis C that has serious side effects.