It is the second upset in as many days at the Masters with world No. 1 seed Novak Djokovic eliminated in the previous round.
Fognini produced a sensational display to take the first set and although Nadal momentarily fought back from 5-0 down in the second, the Italian secured the memorable victory in 1 hour and 36 minutes.
The Italian had beaten Nadal twice before on clay, and also once at the U.S. Open in five sets, but this was arguably the most impressive.
Nadal's last defeat here was also in the semifinals, against Djokovic in 2015. He had not lost a set at the clay-court tournament since conceding one in the second round against Britain's Kyle Edmund in 2017.
"It was a tough day and [Fabio] was a difficult opponent," said Nadal. "I am coming from low moments in terms of injuries, and in terms of the mental side it has not been easy to accept all the things that have been going on... It was this kind of day that everything was wrong."
Lajovic won 10 straight games to open up a 4-0 lead in the second set before Medvedev finally held serve. But after saving one match point, the Russian player tamely hit a return long on his opponent's next opportunity.
The Serbian will feature in his first Masters final and he is the lowest-ranked Monte-Carlo finalist since 2001.
"It was an incredible match today," said Lajovic. "I had the worst nightmare, falling down 5-1. But I won 10 games in a row, so I was able to find my rhythm and my game. In windy conditions like today, it was impossible to play real tennis and in the end I was able to hit my forehands better than him. I'm still unaware of my achievement in Monte-Carlo."
Information from Associated Press contributed to this article.