Drug companies Merck (MRK 0.21%) and AbbVie (ABBV -0.15%) have been two of the best pharmaceutical investments, easily delivering better total returns than the S&P 500 average over the past three, five, and 10 years.

However, as it is often said, past performance is no guarantee of future success. Both companies are coming off record years in terms of revenue and face the prospect of decline in the next few years because of significant patent expirations affecting their lead drugs.

I don't think it's time to abandon either stock, however. The two companies have been preparing for these patent cliffs for a while, and through their huge pipelines and willingness to spend to acquire promising therapies, they have the wherewithal to get back to increasing revenue in a short period of time.

Charts showing AbbVie's and Merck's total returns beating the S&P 500, and both companies' EPS up since 2018.

ABBV Total Return Level data by YCharts

Merck investors don't need to panic

Over the past five years, Merck's shares have grown 93%. In that same period, the company's annual revenue has climbed 40% while its annual earnings per share (EPS) has grown 146%.

The key to that strong performance was immuno-oncology blockbuster Keytruda, which was responsible for $21 billion in 2022 sales, a third of the company's sales. Keytruda has received U.S. Food and Drug Administration (FDA) approvals this year for two new indications.

However, the drug could face biosimilar competition as early as 2028. That concern explains why the stock is only up slightly more than 2% so far this year, despite a record year in revenue last year.

Merck has been preparing for Keytruda's loss of exclusivity. It hasn't been shy about acquiring key assets while spending heavily on its own pipeline. Its biggest acquisition recently was its $10.8 billion purchase of Prometheus Biosciences. Prometheus isn't profitable and it doesn't have any approved drugs yet, but it has a potential blockbuster in PRA-023, which has done well in trials to treat ulcerative colitis, Crohn's disease, and other autoimmune conditions. Merck has renamed the therapy MK-7240.

Merck's pipeline is particularly strong, with 120 programs, including more than 80 in phase 2 trials and more than 30 in phase 3 trials. The company received two FDA approvals for new indications in June, including Prevymis to stop cytomegalovirus (CMV) infections in adult kidney transplant recipients, and a new indication for Lynparza (for which Merck shares profits with AstraZeneca), as a combination therapy with abiraterone and prednisone or prednisolone to treat adults with castration-resistant prostate cancer with deleterious or suspected deleterious BRCA-mutated (BRCAm) genes.

Another reason to like Merck as a long-term buy is its quarterly dividend, which it has increased for 12 consecutive years, including a boost of 5.8% effective this year, to $0.73 per share. The yield on the dividend is roughly 2.92%. With a payout ratio of 54%, it's likely the company will continue to raise the dividend.

AbbVie will survive, even thrive, after Humira

AbbVie's stock is down 17% so far this year. The company's best-selling drug, Humira, is facing biosimilar competition for the first time in the U.S., and seeing declining sales after years of being the world's top-selling drug.

Like Mark Twain, though, reports of AbbVie's demise have been greatly exaggerated. The point is that AbbVie will do just fine in time despite lowered revenue expectations from Humira, which was responsible for 36% of the company's 2022 revenue.

AbbVie's pipeline includes 90 programs, with more than 50 of them in phase 2 or phase 3 trials. Not counting Humira, AbbVie had 11 therapies with $1 billion or more in sales last year, including two rising immunology drugs, Skyrizi and Rinvoq. 

The company has predicted the two could bring in more than $15 billion in annual combined sales by 2025. They're already on the way, with $6.5 billion in sales last year. They are being heavily marketed by AbbVie as they continue to add indications for the two.

In May, the FDA approved Rinvoq as a treatment for Crohn's disease for adult patients who have not responded well to one or more tumor necrosis factor (TNF) blockers. The drug is already approved to treat rheumatoid arthritis, psoriatic arthritis, and ulcerative colitis, along with active ankylosing spondylitis and non-radiographic axial spondyloarthritis, two inflammatory diseases that frequently affect the spine.

Skyrizi is approved to treat psoriatic arthritis, plaque psoriasis, and Crohn's disease and is coming off a positive phase 3 trial in March to treat ulcerative colitis. 

Like Merck, AbbVie is willing to supplement its revenue through acquisitions. In October, the company purchased private biotech company DJS Antibodies for $255 million. The company's lead therapy is DJS-002, which is in pre-clinical studies to treat idiopathic pulmonary fibrosis and other fibrotic maladies.

The company's dividend makes the stock even more worth holding on to today. Counting AbbVie's time as a division of Abbott Laboratories, the quarterly dividend has increased for 51 consecutive years, including a boost of 5% this year to $1.48. At around 4.7%, the yield is more than double the S&P 500's payout.