It was supposed to be the year that the U.S. lost faith in Silicon Valley. Big names in tech were plagued with bad headlines in 2019, from antitrust probes to mounting scrutiny over data privacy to technology executives facing bipartisan grillings on Capitol Hill.

That didn’t stop tech stocks from posting their best year in a decade.

Technology...