Big oil companies and traders are stashing millions of barrels of crude on massive tankers bobbing in the ocean, in a bid to profit from a quirk in oil markets.

Instead of moving crude from one port to another, a growing number of tankers are serving as floating warehouses for companies including Sinopec Ltd. and Vitol Group, according to people with knowledge of their operations. Other companies such as Mercuria Energy Group are...