A climb in technology shares buoyed U.S. stocks, boosting the Nasdaq Composite to a fresh record.

The gains lifted Apple, Google-parent Alphabet, Microsoft, Amazon.com and Facebook to records, the first time those companies—the five largest by market capitalization—all reached highs on the same day, according to WSJ Market Data Group.

Technology...