CARACAS, Venezuela—China has been holding talks with Venezuela’s political opposition to safeguard its investments in the troubled Latin American nation, hedging its bets as pressure builds on Nicolás Maduro, the embattled leader for whom Beijing has been a vital ally.

Chinese diplomats, worried over the future of its oil projects in Venezuela and nearly $20 billion that Caracas owes Beijing, have held debt negotiations in Washington in recent weeks with representatives of Juan Guaidó, the opposition leader heading the U.S.-backed...