Substitute Mikel Merino scored a late winner to put Spain in the quarter-finals with a 1-0 victory over Portugal and end Cristiano Ronaldo's World Cup career on Monday.