But now the English actor has finally wrapped up his role as the iconic wizard, having completed work on the final film in Jackson's Hobbit trilogy, There and Back Again.

The director posted a photo of himself with McKellen on set in New Zealand.

PHOTOS: Elijah Wood in 'Hobbit' and 16 Other Cameos in Prequels, Reboots and Remakes

"Seconds ago we finished our last shot with Gandalf. The end of an incredible adventure that began in 1999. I'm feeling very sad right now," Jackson wrote.

McKellen, now 74, was 59 years old at the start of the first shoot for Fellowship.

The second installment in the Hobbit series -- which sees Bilbo Baggins (Martin Freeman), joining 13 dwarves on a quest to reclaim the Lonely Mountain from the dragon Smaug (voiced by Benedict Cumberbatch) -- will hit theaters on Dec. 13 via Warner Bros.

The final installment, There and Back Again, opens in theaters one year later, on Dec. 17, 2014.