Gonzalo García has scored in stoppage time as Real Madrid escaped an upset by defeating Leganes 3-2 to reach the semifinals of the Copa del Rey.