The politically savvy comic will host his final show on August 6, after a decade-and-a-half in the job.
In 2010, Obama became the first sitting president to appear, and Tuesday marked his third appearance since entering the White House.
Obama has been on the show seven times in total.
Read: Religious scholar says anti-Muslim fervour is rising in America
"I cannot believe you are leaving before me," Obama said, joking that he would issue an executive order to stop Stewart from leaving.
"It's being challenged in the courts," he added, a wry reference to his repeated legal battles with Republican rivals.
Stewart joked: "It's a states' rights issue."
When Obama made a first pitch for his diplomacy with Iran, Stewart saw an opening, asking "whose team are we on in the Middle East?" before laying out the amalgam of alliances and enmities that crisscross the region.
Read: Jon Stewart to leave The Daily Show 'later this year'
"That's not quite right," Obama joked, "but that's okay," before Stewart interrupted: "Who are we bombing?"
Obama went back repeatedly to the issue of Iran, using Stewart's vast audience to make his pitch.
"I really want people to pay attention to this issue," Obama said, urging citizens to engage by contacting their members of Congress.
"If people are engaged eventually the political system responds," he said.
Stewart shot back: "Is that the advice that you then bequeath to future President Trump?"
Obama said he was sure the Republicans were enjoying the real estate mogul's often controversial candidature.
"Anything that makes them look less crazy" said Stewart.
Stewart will be replaced by South African comic Trevor Noah.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ