NEW YORK—U.S. stocks shook off early declines and closed out the last trading day of the month with modest gains on Friday as a rise in Microsoft helped offset declines in Amazon and Apple after disappointing quarterly earnings from the online retailer and iPhone maker.
Microsoft Corp.’s shares closed at a record high of $331.62 and ended the session with a market capitalization of $2.49 trillion, surpassing Apple Inc.’s market cap of roughly $2.48 trillion.