In a way, they’re both a product of an America that was fed up with President George W. Bush. Without public frustration over Bush and his execution of the U.S.-led war in Iraq, comedian Jon Stewart’s The Daily Show would not be such a cultural force. And without that same angst, Barack Obama likely would have faced a tougher climb from his role as a little-known state senator from Illinois.

Yet, here they were Tuesday night, airing long-simmering frustration with politics and the media — and showing a readiness to try new gigs — as now-President Barack Obama made a final appearance as a guest on the late-night comedy show Stewart is soon to leave.

“You’ve been a great gift to the country,” Obama told Stewart as he left the New York soundstage where The Daily Show is taped. Obama was making his third appearance as President and seventh overall to chat in front of an audience that skews younger and more liberal than almost any other program on television.

It was classic Obama (professorial, dry and critical) paired with Stewart (sarcastic, glib and skeptical) in a 30-minute television segment that, perhaps, is a fitting illustration of liberal frustration with this President and vice versa. Obama won two hard-fought elections in part by motivating Stewart’s viewers to volunteer, donate and vote. But as both the President and the host are heading for the door, it’s a moment of inflection for each man’s audience. It’s not yet clear if the show or the political coalition can be passed on to a successor.

“Are you feeling like seven years in,” Stewart began one question. Obama cut in: “I finally know what I’m doing?”

The pair, more relaxed than at any other point during their seemingly friendly relationship, traded jokes and debated American policy, often with little transition between the two. Although the exchanges packed plenty of laugh-out-loud laughs from the audience and the two men on stage, Stewart used his last chance to interview Obama for the Comedy Central program to push him, especially on foreign policy.

“Whose team are we on?” Stewart asked, noting the strange alliances that the U.S. finds itself in while working to stabilize the fractured Middle East. Obama took issue with Stewart’s analysis — shared by foreign policy think tanks across the political spectrum. The details did not allay the host, who is stepping down after 16 years anchoring the nightly program that blends political commentary, comedy and celebrity interviews.

“Who are we bombing?” Stewart asked.

At another point, Stewart noted that the U.S.-brokered deal to curb Iran’s nuclear program resulted not from military force but through negotiations. “This new thing, you called it earlier, ‘diplomacy.’ That sounds interesting,” Stewart said to laughter. “But we still get to bomb people at some point?”

Stewart’s program rose in prominence and popularity during the lead-up to the 2003 invasion of Iraq and the subsequent mismanagement of that war. Stewart’s coverage of the 2004 presidential race cemented him as a serious player in political journalism, although some in that stable still bristle when surveys find his show has a greater and more impactful reach than other more traditional newscasts.

If Stewart rode that popular frustration with foreign policy under Bush to ratings and critical acclaim, Obama channeled those same emotions to the U.S. Senate in 2006 and then to the White House in 2008. But the liberal fervor that propelled Obama to power has seemed to lose its power, especially as he has struggled to deliver on campaign promises such as closing the prisons at Guantanamo Bay, Cuba.

White House officials privately grumble that the liberal wing of the Democratic Party has not appreciated how much Obama has accomplished. Obama himself has often complained that too much emphasis is on the trivial. Last week, for instance, Obama confronted on live television one network correspondent whose question on the freshly-minted Iranian deal he found ridiculous.

“The media. You love them. They love you,” Stewart told Obama with impish sarcasm. The President did little to hide his amusement at such a statement.

“The media is a bunch of different medias. There are some who get on my nerve more than others,” Obama said. “I think it gets distracted by shiny objects and doesn’t always focus on the big tough choices and the decisions that have to be made.”

Both Obama and Stewart have expiration dates that are fast approaching. Stewart’s final episode as host is slated to air Aug. 6 — the same day Republican presidential hopefuls will face off in Cleveland for their first debate. Obama still has a way to go before he leaves the White House on Jan. 20, 2017. Yet Obama and Stewart each acknowledge they have an eye on the door.

“You’re also senioritis, yes?” Stewart asked Obama. “What do you’ve got? A year?”

Dryly, the President did not miss a beat: “I can’t believe that you’re leaving before me.”

Get our Politics Newsletter. The headlines out of Washington never seem to slow. Subscribe to The D.C. Brief to make sense of what matters most. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

Write to Philip Elliott at philip.elliott@time.com.