Gonçalo Ramos scored a stoppage time winner to send Portugal past Croatia into a last 16 showdown with Spain.
The goal should have ended a compelling game at the Toronto Stadium but it launched a high-voltage climax in which Josko Gvardiol's strike was ruled out for offside following a review by the video assistant referees.