In a basketball tournament every two teams play two matches. As usual, the winner of a match gets $2$ points, the loser gets $0$, and there are no draws. A single team wins the tournament with $26$ points and exactly two teams share the last position with $20$ points. How many teams participated in the tournament?
1. Let \( n \) be the number of teams in the tournament. Each pair of teams plays two matches, so the total number of matches is \( 2 \binom{n}{2} = n(n-1) \).

2. Each match awards 2 points (2 points to the winner and 0 points to the loser). Therefore, the total number of points distributed in the tournament is \( 2 \times n(n-1) = 2n(n-1) \).

3. Given that one team wins the tournament with 26 points and two teams share the last position with 20 points each, we need to account for the points of the remaining \( n-3 \) teams.

4. Let \( a \) be the number of teams scoring 24 points, and \( b \) be the number of teams scoring 22 points. Then, we have:
   \[
   a + b = n - 3
   \]
   and the total points scored by these teams is:
   \[
   26 + 2 \times 20 + 24a + 22b = 2n(n-1)
   \]

5. Simplifying the equation for total points:
   \[
   66 + 24a + 22b = 2n(n-1)
   \]

6. Substitute \( a + b = n - 3 \) into the equation:
   \[
   66 + 24a + 22(n-3-a) = 2n(n-1)
   \]
   \[
   66 + 24a + 22n - 66 - 22a = 2n(n-1)
   \]
   \[
   2a + 22n - 66 = 2n(n-1)
   \]
   \[
   2a = 2n(n-1) - 22n + 66
   \]
   \[
   a = n(n-1) - 11n + 33
   \]

7. Since \( a \geq 0 \), we have:
   \[
   n(n-1) - 11n + 33 \geq 0
   \]
   \[
   n^2 - 12n + 33 \geq 0
   \]

8. Solving the quadratic inequality \( n^2 - 12n + 33 \geq 0 \):
   \[
   n = \frac{12 \pm \sqrt{144 - 132}}{2} = \frac{12 \pm \sqrt{12}}{2} = 6 \pm \sqrt{3}
   \]

9. Since \( n \) must be an integer, we test the integer values around the roots:
   \[
   n \geq 12
   \]

10. From the condition \( b \geq 0 \):
    \[
    b = n - 3 - a = n - 3 - (n(n-1) - 11n + 33)
    \]
    \[
    b = -n^2 + 12n - 36
    \]
    \[
    -n^2 + 12n - 36 \geq 0
    \]

11. Solving the quadratic inequality \( -n^2 + 12n - 36 \geq 0 \):
    \[
    n^2 - 12n + 36 \leq 0
    \]
    \[
    (n-6)^2 \leq 0
    \]

12. The only solution to \( (n-6)^2 \leq 0 \) is \( n = 6 \), but this contradicts our earlier condition \( n \geq 12 \).

13. Therefore, the only possible value for \( n \) that satisfies all conditions is \( n = 12 \).

The final answer is \( \boxed{12} \)