Investors are fleeing U.S. stocks at a rapid clip as ongoing market volatility and trade tensions push them to seek safety among less risky assets such as U.S. Treasurys.

Nearly $20 billion was pulled from long-term mutual funds and exchange-traded funds focused on large-cap stocks in June, handing those funds their biggest month of outflows in at least a decade, according to data provider Morningstar LLC. Outflows across the stock market have continued into July, though the pace has somewhat slowed.

The...