Achraf Dari equalized almost immediately, heading in a loose ball from close range.
Secured their second-ever third-place finish (after 1998) and their third top-three finish in six World Cup appearances.
Joško Gvardiol scored with a diving header following a set-piece routine.