Mercutio provides most of the comic relief in the play. This allows the audience to laugh in between the more serious parts of the play. I think Shakespeare felt his audience needed this relief in order to get through the tragedy of the death of Romeo and Juliet at the end. When Mercutio is killed by Tybalt, this begins the unraveling of the plan the Friar has put together for the couple. The audience then knows that tragedy is to follow when the fun-filled, humorous character of Mercutio is slain. Mercutio also plays a foil to the serious character of Romeo.
Mercutio is introduced in act 1 scene iv as he and Romeo go to crash the Capulet party. The scene captures the essence of Mercutio as a joking foil to Romeo who gets Romeo to not take life so seriously. Shakespeare uses Mercutio as a character that creates things to happen and then uses Romeo as the one to act. For example, although it is Mercutio's idea to go to the party, Romeo is the one who ends us falling in love. And while it is Mercutio who begins the fight with Tybolt, it is Romeo who ends up killing him, and getting banished. It is theorized that Shakespeare kills of Mercutio because he was getting to be too interesting a character. With his wit and jest, to let him live would pull attention away from Romeo and Juliet.
There is a very good and full article all about the character of mercutio here: http://www.enotes.com/romeo/777