Portugal advanced to the quarterfinals for the third time, after 1966 and 2006, and will play Morocco.