SAN FRANCISCO — Apple, which had long deferred paying taxes on its foreign earnings and had become synonymous with hoarding money overseas, unveiled plans on Wednesday that would bring back the vast majority of the $252 billion in cash that it held abroad and said it would make a sizable investment in the United States.

With the moves, Apple took advantage of the new tax code that President Trump signed into law last month. A provision allows for a one-time repatriation of corporate cash held abroad at a lower tax rate than what would have been paid under the previous tax plan. Apple, which has 94 percent of its total cash of $269 billion outside the United States, said it would make a one-time tax payment of $38 billion on the repatriated cash.

For years, Apple had said it would not bring its foreign earnings back to the United States until the corporate tax code changed, because such a move would be too costly. Now Apple’s bet to hold back on paying such taxes is reaping rewards under the Trump administration.

In return, Mr. Trump and other Republicans can point to Apple as having come around because of their legislative action. The $38 billion tax payment from the Silicon Valley giant is set to be among the biggest payouts from the tax bill, and Apple said it would put some of the money it brought back toward 20,000 new jobs, a new domestic campus and other spending.