There appears to be some debate over this (on IMDb boards and Rotten Tomatoes et al), but I found a Wikipedia snippet that suggests the following: Film scholar David Bordwell, writing in Film Viewer's Guide, mentioned the (un)reality of the ending as a topic for debate.
A number of scenes in the film — Rupert and Jerry in the restaurant, Jerry meeting Rupert after having listened to his tape and calling him a genius, Rupert getting married "live" on Jerry's show — exist solely in Rupert's imagination, and Bordwell suggested that some viewers would think the final sequence is another fantasy.
movies.stackexchange.com/users/382/Nobby
The background curtains, as stated above, look like prison bars.
In addition, he's wearing a very loud red suit consistent of what would be worn by someone in prison.
Finally, if you happen to look he positions his hands in what would normally be some form of a restraint position.
All this, in addition to the very weak material in his stand up would lead one to believe that he's imagining all of this from some from of Prison/Mental institution.
movies.stackexchange.com/users/51381/Bob A' Booey
That's clearly Pupkin's imagination.
Think about all the times he was day dreaming, it was EXAGGERATED, a lot, and now read the last lines of the script (which, by the way, different from the original draft where it is clearly not day dreaming, here is instead not that obvious..), after stating that the biography has been sold for a million ( a million! ) dollars, and that a movies will be made on it soon, and that "he and his people were weighing attractive offers": And now, ladies and gentlemen the man we've all been waiting for, and waiting for .Would
you welcome home please television's brightest new star
The legendary, inspirational, the one and only king of comedy !
Ladies and gentlemen, Rupert Pupkin!
Rupert Pupkin, ladies and gentlemen!
Let's hear it for Rupert Pupkin!
Wonderful!
Rupert Pupkin, ladies and gentlemen!
Rupert Pupkin, ladies and gentlemen!
Let's hear it for Rupert Pupkin!
Wonderful !
Rupert Pupkin, ladies and gentlemen!
You get it..
This is no different from when, during the movie, his teacher is thanking him because.. he changed their lives.. :D
movies.stackexchange.com/users/83012/nnsense
Having had this discussion many times, I am convinced it is a fantasy.
My primary reasoning is that, beyond the symbolism people have already pointed out, his end rise to "King" level doesn't really make that much rational sense.
The short prison sentence, the fact that somehow he would be even more popular 6 years later, and the fact that he is just given a show of his own are all incredibly extreme.
I believe the lack of Jerry in the final sequence is meant to show a change in his fantasy life.
He no longer needs Jerry to be a crutch for his fantasies, he can pour them all into himself.
movies.stackexchange.com/users/59739/josh allen
Fantasy.
And here is my theory:Remember that every scene in Rupert's imagination is outweighed by scenes in Rupert's reality.
Now, think of it like this: Rupert's fantasy = positive life situation.
Rupert's reality = negative life situation.
The movie follows a certain pattern of balance​, it follows a shift of positive fantasy and negative reality.
For every negative situations in his reality, it had to be balanced by the same amount of positive situations in his fantasy.
For example, he got his tape rejected by Jerry (negative reality), next scene shows Jerry praising him (positive fantasy).
We find another example at the end of the movie:
Rupert goes to jail (very negative reality).
If the movie follows this pattern then the last scene with Rupert's success, a very positive situation, has to be fantasy.
movies.stackexchange.com/users/79310/Zhen 2012
I think the ending is a fantasy by the sheer magnitude of the reception he receives in the end...which is consistent in regard to viewing himself as the KING...
movies.stackexchange.com/users/9140/bharat wadhawan
When Rupert is being introduced during the end scene the curtains in the background resemble prison bars, quite a strong hint towards reality or fantasy.
The point is there is evidence to both sides of the argument, it's up to the viewer to make a decision depending on their interpretation of the film.
That's what the director has intended to do.
movies.stackexchange.com/users/14023/Tom
In the final scene of Martin Scorsese's 'King of Comedy' a news report suggests that Rupert Pupkin (played by Robert De Niro), after coming out of prison, becomes a sensation and releases his much awaited autobiography. At the same time he is shown to be holding various offers for shows.  Is it possible that he would have imagined this bit too like his previous conversations and stage shows with Jerry Langford? Is there any suggestive evidence leading to reality or otherwise?
Was the success of Rupert Pupkin real in King of Comedy?
movies.stackexchange.com
<plot-explanation><ending><the-king-of-comedy>
movies.stackexchange.com/questions/9025
movies.stackexchange.com/users/3538/Qrious
It is up to the viewer to make a decision based on their interpretation of the film. When Rupert is being introduced in the end of the film the curtains in the background resemble prison bars which hint towards reallity and fantasy but it is clearly Pupkin's imagination. That's clearly Pupkin's imagination.
When Rupert is being introduced during the end scene the curtains in the background resemble prison bars, quite a strong hint towards reality or fantasy. That's what the director has intended to do, that's clearly Pupkin's imagination.