Tim Cook, chief executive officer of Apple, Inc. Daniel Acker | Bloomberg | Getty Images

2019 was a historic year for the S&P 500, and the benchmark has two stocks to thank. Apple and Microsoft, which surged 85% and 54% this year, respectively, together accounted for nearly 15% of the S&P 500's advance in 2019, according to S&P Dow Jones Indices. Their influence to the cap-weighted index this year is greater than the next eight biggest contributors combined. The S&P 500 rallied more than 28% this year, its best annual performance since 2013.

The mega-tech duo's epic run this year also lifted them above the coveted $1 trillion level in market value, making them the only two U.S. companies in that elite market-cap club. Shares of Apple posted their best year since 2009 as investors shook off trade-induced worries and turned bullish on its services and wearable device businesses. With the launch of Apple TV, Apple Watch and Airpods, Apple managed to offset some of the loss from waning demand for iPhones. Enthusiasm for the upcoming 5G cycle has also lifted the stock.

Apple's rally also defied analysts' wisdom. In fact, Apple has seen the biggest increase in analyst sell ratings this year among the 40 biggest companies, according to Bespoke Investment Group. It's no surprise that Microsoft emerged as the other powerhouse that did much of the heavy lifting this year. The tech giant enjoyed strong growth in its core personal computing business as well as Windows commercial products, cloud services and gaming. Earlier this year, Microsoft also snagged a hotly contested $10 billion defense contract, beating out Amazon. Bank of America named Microsoft one of its top software picks for 2020, saying the growth in its cloud computing segment could fuel a big run next year. The stock is also on track for its best annual performance since 2009.