WASHINGTON—A $1.3 trillion spending deal that President Donald Trump signed Friday includes a measure that gives U.S. investigators access to data stored on overseas cloud servers, resolving a long-running legal battle between law enforcement and big tech companies.

But the measure drew widespread criticism from privacy and human-rights activists, who suggested U.S. tech companies—under pressure in Washington—had retreated on the issue. They also suggested the bill could leave data stored in the U.S. vulnerable to demands...