I think the only way the US beats Portugal and not get in, is for Ghana to beat Germany, and then Germany beats the US by 5 or 6 goals, and Ghana beats Portugal.
I think the latter is extremely unlikely. Germany can beat Ghana, it can beat the US but it won’t be a blowout and Portugal should beat Ghana.