South Wales Police said the problem was caused by poor weather conditions.
The road was shut between junction 35 (Pencoed) and junction 36 (Sarn) for about one hour.
No injuries were reported.
The M4 has reopened after being closed in both directions in the Bridgend area following several accidents.