"You've been taking a lot of shots at my job, I've decided I'm going to go ahead and take a shot at yours," Obama said before sitting down alone behind Colbert's desk.
"As you know I, Stephen Colbert, have never cared for our president," Obama proceeded, pretending to be the comedian.
"The guy is so arrogant, I bet he talks about himself in the third person," he said to laughter and applause.
The president has appeared regularly on daytime and nighttime talk shows to reach specific constituency groups, including young people, who are a key Colbert demographic.
In the surprise opening segment, Obama read the remarks that were supposedly prepared for Colbert while flippant commentary appeared on the screen next to him, drawing howls from the audience.
"Young people don't watch real news shows like this one," Obama quipped about "The Colbert Report," which follows the format of a traditional news program.
"They watch comedy shows. And I just don't see the president going on one of those. They're beneath his dignity."
The show reverted to its typical question-and-answer format once Colbert returned to the stage. Colbert tried to get Obama to confirm one of the numbers from the nuclear launch codes to which the president always has access. Obama demurred.
He pushed Obama to rate himself as a great or "the greatest" president. Obama demurred again.
On policy matters, Obama repeated his stance that approval of TransCanada Corp's controversial Keystone XL pipeline from Canada would be based on whether it would exacerbate climate change. He noted the project would not create many jobs.
When Colbert highlighted the president's positive job creation record, he joked that Obama had provided a lot of employment for secretaries of defense.
"That's boosted our numbers a little bit," Obama replied, appearing unamused.
Under pressure, Secretary of Defense Chuck Hagel recently announced he was stepping down and Obama has nominated former Pentagon official Ash Carter to take his place.
If confirmed, Carter would be the fourth person to serve in the role under Obama.

Latest News from World News Desk