A massive cyberattack scrambled computer systems in dozens of countries on Friday, in an assault computer-security experts said relied on a software vulnerability that the U.S. National Security Agency had allegedly exploited earlier.

U.S. delivery giant FedEx Corp. was among those caught in the cyberattack. England’s National Health Service said 16 hospitals and clinics were forced to cancel appointments and divert ambulances as a result of the cyberattack. Brazil’s social security agency shut down its systems after being...