Foreigners now hold more than $13 trillion in American securities, a record set as the U.S. seeks to assert itself as the safest port in troubled global waters.

China and Japan combined owned more than $3.4 trillion, including $2.4 trillion in debt, a number that has grown since the data set was compiled.

The total value of U.S. stocks and bonds under foreign ownership rose 6.5 percent in 2012, with stocks actually rising more on a percentage basis, according to the most recent data from the U.S. Treasury.

Foreign holdings have more than doubled since 2005 and are getting close to the $15 trillion total size of the U.S. economy

Of the $13.26 trillion total, $4.2 billion was held in stocks, a 10.6 percent increase from 2011. Long-term debt holdings grew to $8.2 trillion, a 6.2 percent annual rise.

(Read More: The Economy May Stink, but the Market Doesn't Care)

Holdings of short-term debt actually contracted to $811 billion, falling 7.6 percent.

The totals compare to about $60 trillion in total U.S. debt and equity holdings, meaning that foreigners hold about 20 percent. The greatest percentage of any class is in marketable Treasurys, which are owned 52 percent by investors outside the U.S.

The move to U.S. assets came as the American stock and bond markets delivered solid returns for the year despite a stubbornly slow economic recovery, political turmoil and headwinds from other shores.

In fact, it may have been that geopolitical turmoil, particularly involving the European sovereign debt crisis and slowing growth in China, that helped buttress foreign money into the country.

(Read More: Tony Blair Warns of 'Fragile' Europe, Harsh Austerity)

Japan leads the way in American holdings with $1.83 trillion, the great majority of which was in bonds. China was second at $1.59 trillion, of which $1.18 trillion was in debt, a number that has increased to $1.22 trillion since the June 30, 2012, cutoff for the data.

Interestingly, the Cayman Islands is the third-biggest holder of securities and the largest overall of stocks, with $516 billion. That is likely due to the attractiveness of the region as a tax haven for American cash.

(Read More: Caribbean Bank Accounts Are Next on IRS Hit List)

The gain in U.S. assets has come with the help of the Federal Reserve. The central bank has been purchasing $85 billion a month in debt, which in turn has helped provide liquidity to the equity markets.

(Read More: Wall Street: Fed Will Print Money Until at Least 2014)

Central banks, though, are getting increasingly more competitive, and the Fed will have plenty of competition this year from global money printers seeking to draw foreign capital.