Novartis AG agreed to buy biotechnology company Avidity Biosciences Inc. in a deal valued at $12 billion, making it the Swiss drugmaker’s biggest acquisition in more than a decade and adding several potential blockbuster treatments as generic competition looms for its current top-sellers.

