Comic relief is the inclusion of a humorous character, scene, or witty dialogue in an otherwise serious work, often to relieve tension.

Sometimes comic relief characters will appear in fiction that is comic. This generally occurs when the work enters a dramatic moment, but the character continues to be comical regardless. External comic reliefs and internal comic reliefs can be separated based on the engagement within the story and the effect on the audience. An internal comic relief is a character or moment where the story is written in the story itself. Others are involved and can laugh along with the humor. While external comic relief moments occur whenever the audience is supposed to laugh but the characters do not.

Comic relief moments serve the purpose to allow the audience to break from the dark and heavy content. It can be a breath of fresh air and advance the plot, though most people view it as a distraction.

More Info: en.m.wikipedia.org