It's true.
Since almost all criteria are the same (points, goal difference, goals scored etc.) they look on fair play points based on red and yellow cards. Yellow is minus one point and since Portugal has 2, Spain 1, they are ahead. If this is even, then they determine it by a draw.