Merz elected German chancellor after initial shock defeat