The seven-time Roland Garros champion twice let a lead slip away in the fourth set, then came from behind in the fifth set to beat the world's No 1-ranked player 6-4, 3-6, 6-1, 6-7, 9-7.
Djokovic blew an easy overhead on the opening point on the final game and went on to lose serve at love, sending his final forehand long.
Nadal improved to 58-1 at Roland Garros, including five wins over Djokovic. The French Open remains the only major title Djokovic has yet to win.
Nadal is trying to become the first man to win eight titles at the same grand slam event.
He will play fellow Spaniard David Ferrer in the final.
"It's a very special win for me and congratulations to Novak," Nadal said. "He's a great champion and he is going to win here at Garros one day."
Nadal leads the series between the players, 20-15. However, he had lost the pair's only other five-setter, the record-setting 2012 Australian Open final.
"When I was serving for the match it was against the wind so I knew that it would be a tough game. It was a similar match to the one in Australia and he won. This time it is me that won and that is what makes sport so big."
Nadal will be appearing in his ninth final since returning from a seven-month injury lay-off.
"During these seven months out of the game there were some low moments, but everybody supported me and there was a lot of positive energy."
In the fourth set Nadal twice was a break up, and twice found himself two points from victory, but Djokovic summoned his best tennis of the day and won 10 of the final 13 points in the set to even the match.
Nadal double-faulted in the first game of the final set, and Djokovic broke to take the lead. But there were more plot twists to come.
Serving at 4-3 in the fifth set, at deuce, Djokovic came forward to put away a winner, but his momentum carried him into the net and Nadal was awarded the point.
Three points later Djokovic drove a forehand into the net to lose the game and even the score again.
As the tension built, Nadal pulled off the shot of the day - and perhaps the tournament - in the 14th game of the set. Retreating for a lob, he flicked the ball between his legs with his back to the net.
That left Djokovic with an easy overhead, but he dumped it into the net, and the crowd roared at the improbable sequence.
The mistake did not cost Djokovic, who won the game on the next point for 7-7. But the next blown overhead did, and it appeared to rattle him as he lost the next three points and the match.
The last shot came 4 hours, 37 minutes after the first.
A triumphant Nadal grinned, threw an uppercut and answered the fans' roar with applause for them.
Then he gestured graciously toward the defeated Djokovic.
Afterward, the Serb said: "I gave my best. I really did. I really tried to come back. The third set wasn't great at all. I just dropped physically. He used it. I managed to come back and start playing really, really well as the match was going on, but it wasn't good enough."
In the second semi, Ferrer breezed past home favourite Jo-Wilfried Tsonga to set up an all-Spanish menís final.
Tsonga had high hopes of reaching the final as he powered his way through the draw in Paris, including defeating Roger Federer in straight sets on his way to the semi-finals.
However, the Frenchman found No 4 seed Ferrer much too powerful and he went down without much of a fight in straight sets 6-1, 7-6, 6-2.
It was all one-way traffic in the first set as Ferrer rapidly opened up a 5-0 lead, breaking Tsonga twice, before his opponent got on the board.
And the crowd was almost silent when he wrapped up the opener two games later.
The second was a much tighter affair as Tsonga started to find his rhythm. He broke for a 3-0 lead but was pegged back to 3-3 shortly afterwards.
The pair then traded breaks as Tsonga and the partisan crowd became more vocal, but Ferrer ran away with the tie-break 7-3 to gain a two-set lead.
Ferrer looked to be nearly home and dry when he opened up a 4-1 lead in the third before Tsonga put up a final show of resistance.
But it was too little too late as the damage had already been done and Ferrer cantered to victory and a place in his first grand slam final.
Ferrer dominated but Tsonga was given a standing ovation as he left the court.
A similar reception was in store for Ferrer when he followed him off a few minutes later. Now a bigger stage awaits tomorrow.