WASHINGTON—The Customs and Border Protection agency searched a record number of cellphones and other devices at U.S. points of entry last year, the government said Friday, as more travelers carried phones and as the administration stepped up it hunt for national-security threats and smugglers.

In fiscal year 2017, which ended Sept. 30, the government searched the devices of 30,200 people, the vast majority leaving the country, up from 19,051 in fiscal year 2016. More than 80% of the devices belonged to foreigners or legal...