According to UEFA rules for qualifying at the end of the group stage:
In the event of a tie, the direct comparison has priority!

That sounds simple, but it can be tough when 3 teams are tied!
The following example explains how this can look in detail:

Let us assume that the following results were achieved within group F:

Hungary Portugal 1 : 0
France Germany 2 : 1
Hungary France 2 : 3
Portugal Germany 2 : 1
Germany Hungary 1 : 0
Portugal France 0 : 3

Then the following final status of the group table results:

place team points goals
1 France 9 8 : 3
2 Portugal 3 2 : 5
3 Germany 3 3 : 4
4 Hungary 3 3 : 4

At first glance, you might think: There is an error in it!
How can Portugal, with their worse goal difference, be in second place ahead of Germany and Hungary?

This is because the direct comparison is carried out before the goal difference is compared!

The criteria to be checked in the event of a tie are:

  1. higher number of points obtained in all group matches
  2. higher number of points obtained in the direct encounters
  3. higher goal difference resulting from the direct encounters
  4. higher number of goals scored resulting from the direct encounters
  5. repeated application of the criteria 2 - 4 only on the teams that were indistinguishable in the 1st run
  6. higher goal difference resulting from all group matches
  7. higher number of goals scored resulting from all group matches
  8. higher number of wins in all group matches
  9. lower number of disciplinary points total in all group matches
  10. position in the UEFA overall European Qualifiers rankings

When comparing three teams directly, only the points and goals of the three direct encounters count.
If you only consider these three matches, the following table results:

place team points goals
2 Portugal 3 2 : 2
3 Germany 3 2 : 2
4 Hungary 3 1 : 1

All three teams have the same number of points in a direct comparison (Crit. 2).
All three teams have the same goal difference (Crit. 3).
Next, the goals scored are compared (Crit. 4).
At this point, Hungary falls behind Portugal and Germany.

Since Portugal and Germany cannot be distinguished from one another in this first direct comparison, these two are now subjected to a direct comparison again (criterion 5). Since Portugal won against Germany, Portugal got 3 points in this direct comparison, Germany 0 points. Thus Portugal is entitled to the better placement.

* * *