Nadal had been hoping to win the tournament for the first time but crashed out as Medvedev continued the terrific run of form that also saw him triumph at the Paris Masters earlier this month.
Having seen Thiem somehow recover from 0-4 in a deciding tie-break to beat Novak Djokovic in the first semi-final, Medvedev clawed his way back from a set and a break down to beat Nadal 3-6 7-6 (4) 6-3.
So impressive had the Russian been this week, particularly in a convincing win over Djokovic, that most pundits made him the favourite and Nadal was forced to save three break points in the third game.
But the Spaniard has been very upbeat about his own level, even after losing to Thiem, and, when Medvedev failed to land a first serve at 4-3, Nadal pounced.
The world number two had won 71 straight matches in which he had taken the opening set so the size of Medvedev's task was clear.
He received a helping hand at the start of the second set, though, when Nadal double-faulted on break point in the second game, and the second seed had to save another break point to avoid going 5-1 behind.
That looked set to be the crucial moment as Nadal played a brilliant returning game to get back on serve and, the doubts now sown in Medvedev's mind, made it four games in a row to move to the brink of victory.
But the Russian, who did not win a match at The O2 on his debut last year, was not finished and played a perfect returning game to break Nadal to love when he served for the match.
Medvedev opened up a 6-3 lead in the tie-break, partly thanks to an outrageous shank that looped over Nadal, and this time the Spaniard could not find a way back.
Nadal had quickly regained the initiative after losing the second set against Stefanos Tsitsipas on Thursday but here he had to fight off another break point at the start of the decider.
Unusually it was a lack of ruthlessness from the Spaniard that cost him as he failed to take several chances to hold serve at 3-3. Medvedev seized his opportunity and did not let go.
Additional reporting by PA.