Some of the best moments of The Office were Jim's (John Krasinski) brilliant pranks on his desk neighbor, Dwight (Rainn Wilson). However, while the tomfoolery between the two co-workers was a mock rivalry that belied how good of friends they actually were, Jim's best prank on Dwight was also his most sincere.

For a surprise at Dwight and Angela's wedding, Jim got Dwight's best friend and mentor, Michael Scott (Steve Carrell), to visit from Colorado. It was an emotional reunion that Dwight didn't expect, especially since Jim's pranks are usually done to make fun of Dwight. Having Michael at Dwight's wedding meant a lot to him, as Dwight always looked up to Michael and even got his old regional manager position in the show's final episodes.

RELATED: The Office Deleted Scene Confirms a Major Creed Theory

The history of pranks between Jim and Dwight can be traced back to the very first episode of The Office, in which Jim encases Dwight's stapler in a plate of Jell-O. Jim rarely put all his effort into his paper sales job and enjoyed expending that unused brainpower thinking of ways to mess with Dwight. Dwight, on the other hand, took his job very seriously and was criminally naive, which made him a fun target.

Jim would also enlist the help of his partner-in-crime and willing receptionist, Pam (Jenna Fischer), for some bigger stunts, such as getting Dwight to think that Jim was suddenly a different person. This idea saw Jim recruit one of Pam's actor friends, Steve, who is Asian, to impersonate him in the office. Pam plays along, claiming that this man has always been Jim, even putting up family photos that replace Steve with Jim, thus making Dwight believe he has lost his mind.

RELATED: The Office Showrunner Says a Reboot Is 'Not Impossible'

Micheal Scott from the last episode of the office

So, with all this in the back of his head, by the time Dwight's wedding comes around in the final episode, he is wary of Jim pulling a prank on him, making the surprise of Michael all the more meaningful. Originally, Dwight picked Jim as his best man, or "bestest mensch," and tasked him with bringing "good surprises" upon the groom. However, as close as Jim and Dwight had gotten over the years, Jim knew that the real best man should be Michael, who moved to Colorado at the end of Season 7. So, as they're about to head out for the ceremony, Jim tells Dwight he can't continue his role as the best man, just as Michael enters the nearby doorway. When Dwight sees Michael, the two quickly embrace, and Jim's final prank is complete.

Despite a contentious relationship, Dwight and Jim were friends who cared for each other when it mattered the most. Dwight was always there for Pam with fierce loyalty, and Jim went to great lengths to make Dwight's wedding day perfect. In the end, Jim's pranks were not only some of the most beloved parts of the show, but are also what made a paper supply job entertaining for everyone who worked there.

The first two seasons of The Office are now available for free on Peacock, with Seasons 3-9 and The Office: Superfan Episodes available on Peacock Premium for $4.99/month. The ad-free Peacock Premium Plus is $9.99/month.

KEEP READING: Peacock's New Plans Are Priced Based on How Much of The Office You Want to Watch