How? Portugal lost because they got beat worse. If they tied instead of a loss, would they have advanced?
Portugal would have advanced had they tied Germany in the group stage. You get 3 points for a win, 1 for a tie and 0 for a loss. Germany ended with 7 points (2 wins, 1 tie), USA and Portugal had 4 points (1 win, 1 tie, 1 loss) and Ghana had 1 point (1 tie, 2 losses). The US advanced over Portugal because the goal difference was better. They scored more goals and conceded less than Portugal.
This is the knock-out part of the tournament. Need a win to advance, you lose and you go home. They play 90 minutes of this, if it's still tied they play two 15 minute halves, still tied after that they take penalties to decide who wins.