In a world where geopolitical power is increasingly linked to technological advancement, the U.S. has long led its rivals. American companies make some of the world’s fastest computers, deadliest jet fighters and most capable robots.

But China’s growing economy—now the world’s second largest—and huge government investments in technologies are eating away at that edge like never before.

Such...