A lorry got wedged beneath a railway bridge, forcing the road to be shut for hours for recovery work.