In Act 3, Scene 1, Mercutio gets involved in a duel between Tybalt and Romeo and is killed by Tybalt. There are a few different reasons that explain Mercutio's involvement.
The first reason is that, earlier on, Mercutio learned that Tybalt has challenged Romeo to a duel due to feeling insulted by Romeo for his presence at the Capulet ball. As Romeo's friend and knowing what a threat Tybalt poses, Mercutio probably feels a bit angered by Tybalt's challenge. We know that Mercutio recognizes Tybalt to be a dangerous threat as we hear Mercutio explain to Benvolio in Act 2, Scene 4 what a fantastic swordsman Tybalt is, especially in the lines, "...the very butcher of a silk button, a duelist, a duelist! a gentle man of the very first house" (II.iv.23-24).
A second reason is that, like Romeo, Mercutio is very rash, and refuses to listen to Benvolio's advice when he begs Mercutio to get off the street, warning that if they should run into any Capulets, they will probably not be able to avoid a fight. One reason why Mercutio may have been out on the street that day and refused to listen to Benvolio is possibly because he felt so angered by Tybalt's challenge to Romeo. Mercutio probably wanted to start a fight with Tybalt.
The third reason why Mercutio gets involved in the duel is due to the fact that Mercutio has a temper in general. The name Mercutio is derived from the noun mercury, and just like mercury changes so quickly in response to heat, Mercutio's emotions also change very easily, making him easily angered. It is due to his hot temper that Mercutio becomes so infuriated when he sees Romeo acting passively and refusing to respond to Tybalt's challenge. Mercutio becomes infuriated by Romeo's efforts to make peace, as we see when just before Mercutio attacks Tybalt, Mercutio exclaims, "O calm, dishonourable, vile submission!" (III.i.72).
Hence we see that Mercutio becomes involved in the duel because he was angry that Tybalt challenged Romeo and because he has a hot temper. Getting involved in the duel of course cost him his life.
Tybalt is furious at Romeo for attending the Capulet's ball without an invitation so he confronts Romeo later and challenges him to a duel but Romeo doesn't want to duel Tybalt because he has just married Juliet and loves Tybalt since he is Juliet's cousin and doesn't want to fight him so he refuses to duel. Mercutio gets angry at Romeo for refusing the duel and he duels Tybalt instead and dies in the process. Romeo is furious at Tybalt for killing Mercutio so he duels Tybalt and Tybalt dies. Romeo flees and the Prince arrives on the scene with the Montagues and the Capulets. Romeo killed Tybalt and Tybalt killed Mercutio who was the Prince's relative. Romeo is banished from Verona for taking the law into his own hands.