AbbVie (ABBV -2.36%) and Johnson & Johnson (JNJ -0.74%) did something many other stocks didn't last year. They outperformed the S&P 500 index.

These pharmaceutical giants defied the bear market as investors favored the safety of healthcare. After all, even in a difficult economy, people generally still need their medications. And this means healthcare companies may hold up better than others.

This year, though, AbbVie and J&J aren't off to a strong start. They've both declined. But this might be a buying opportunity. After all, these stocks offer a track record of earnings growth and dividend increases.

Which makes the better buy right now? Let's find out.

The case for AbbVie

I've got some good news and some bad news about AbbVie. We'll start with the bad first. The company's mega-blockbuster immunology drug, Humira, recently started facing competition in the U.S. And AbbVie predicts that this will result in a 37% decline in the drug's sales this year. This is key because AbbVie brought in more than $20 billion in revenue at its peak in 2021.

Now let's move on to the good news. AbbVie's two newer immunology drugs -- Rinvoq and Skyrizi -- are on their way to compensating for Humira's loss. The two already are blockbusters, generating billions in annual revenue.

The company predicts that, together, they'll deliver $17.5 billion in revenue in 2025. And in 2027, they should bring in a total of more than $21 billion in revenue. That means they'll actually surpass Humira.

AbbVie also has a portfolio of other blockbusters across treatment areas, from neuroscience to aesthetics. And the company has many potential products in the pipeline, too. These should drive growth over time. In fact, AbbVie is set to dominate the prescription-drug market by 2026, with a 4.2% share, according to Evaluate.

Investors can count on AbbVie for dividend growth, too. It's lifted its quarterly dividend by more than 270% since its beginnings. And today, the company delivers a dividend yield of 3.79%, higher than the industry average.

The case for Johnson & Johnson

J&J is heading for a big transition this year, and one that could help this pharmaceutical giant grow earnings. The company plans on spinning off its consumer health business into a separate entity called Kenvue later in 2023.

Consumer health owns many products we're familiar with -- like Band-Aid brand bandages and Tylenol. But this business is weighing on overall growth at J&J.

The company's two other businesses -- pharmaceuticals and medtech -- reported revenue growth of more than 6% last year. That's as consumer health reported a revenue increase of 3.9% for the year.

Without consumer health, J&J's growth should benefit. At the same time, J&J is investing in growth, too. It completed the acquisition of heart-pump specialist Abiomed in December. Abiomed grew profit over 18 years.

J&J expects the deal to boost the revenue of its medtech business, even adding to adjusted earnings by next year. The Abiomed purchase gives J&J 12 medtech platforms with more than $1 billion in yearly sales.

J&J brought in more than $94 billion in sales in 2022. And the company has more than 100 candidates in the pipeline to keep growth going -- even as it loses exclusivity later this year for blockbuster immunology drug Stelara.

Like AbbVie, J&J is a top dividend stock. As a Dividend King, it's lifted its dividend for more than 50 years.

AbbVie or J&J?

Both of these stocks sound like great buys today, considering their prospects. And the price is right, too. They each trade at around 14 times forward earnings estimates.

But if I could only choose one of these pharma giants to buy right now, I'd go for J&J, and here's why. J&J is heading for a positive move that should support growth -- the spinoff of the consumer health business. And it's right around the corner.

Meanwhile, AbbVie may face some pressure this year as Humira sales fall. Blockbusters do eventually lose patent protection, but considering the number of sales Humira generates, the loss is pretty big. Yes, other drugs will take over and boost growth over the long term. But AbbVie shares may stagnate a bit during this transition.

All of this means, while both stocks are solid long-term buys, J&J may be the one to scoop up first.