The Dow Jones Industrial Average was weak on the final trading day of the year, down 0.2% at 1:25 p.m. EST. If that loss holds, the Dow will end the year up 21.8%.

If you had to guess at the beginning of 2019 what the top Dow stock would be for the year, Apple (NASDAQ:AAPL) probably wouldn't have been your first choice. But initial pessimism gave way to a massive rally. Walgreens Boots Alliance (NASDAQ:WBA) wasn't so lucky; it was one of the few Dow stocks to slump in 2019.

Apple tops the Dow in 2019

2019 started out on a sour note for Apple. On Jan 2, the company slashed its guidance for the 2018 holiday quarter thanks to a handful of issues. Sales were weaker than expected in China thanks to elevated economic uncertainty, trade tensions, and generally sluggish demand. In some developed markets, iPhone upgrade activity was weaker than expected, due partly to price increases.

The iPhone 11 in various colors

Image source: Apple.

The market didn't react well to the news, but the pessimism didn't last long. A quick slump in January gave way to a robust rally that has brought Apple's market capitalization to nearly $1.3 trillion to end the year. Apple stock had gained another 0.2% by Tuesday afternoon, bringing its year-to-date gain to roughly 85.2%.

While Apple's iPhone business is no longer a major growth driver for the company, Apple has found success in other areas. Sales of wearables, including AirPods and the Apple Watch, are booming. And the company's services business is growing quickly as well.

Sales in China began to improve in 2019, but they've deteriorated in the past couple of months. Analysts at Credit Suisse found that iPhone sales in China crashed more than 35% in November, even as the regional smartphone market expanded slightly. Apple clearly still has work to do in one of its most important markets.

Looking ahead, Apple is widely expected to launch a version of its iPhone with 5G technology in 2020. While the jury is still out on how meaningful 5G will ultimately be, at least one analyst sees 5G driving a big iPhone upgrade cycle.

If iPhone sales do improve next year, the tech giant could find itself near the top of the Dow once again in 2020.

Walgreens was the biggest loser

With the Dow up more than 20% in 2019, there were only a few component stocks that failed to move higher. Drugstore chain Walgreens put in the worst performance, down about 13.5% for the year. The stock was up 0.3% Tuesday afternoon.

Things went south early in the year for Walgreens. The company's fiscal second-quarter report in April missed analyst estimates across the board, triggering a steep decline. Included in that report was a dramatic guidance cut. Walgreens said it expected its adjusted earnings per share to be roughly flat in fiscal 2019, down from a previous outlook of 7% to 12% growth.

Fiscal 2020 won't be any better. In its fourth-quarter report in October, the company guided for flat adjusted earnings per share next year.

None of this sat well with investors, but Walgreens stock did get a bump in November after the company began talking to private equity firms about going private. With Walgreens valued at more than $50 billion, plus another $17 billion of debt, any deal would be massive.

Walgreens ends 2019 valued like a has-been. With the company reporting adjusted earnings per share of $5.99 for fiscal 2019, the stock trades for less than 10 times earnings. If Walgreens can show signs of a turnaround next year, the stock could be in for a strong rebound. But if earnings don't start growing again soon, Walgreens investors could be in for another tough year.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.