From 2002-05, LEGO sold Spider-Man themed sets under license from Marvel Entertainment in conjunction with the release of the first two Spider-Man movies. These are commonly known as the Spider-Man 1 and Spider-Man 2 themes. This license was apparently only for Spider-Man and characters in the films and not for other Marvel superheroes.
In October 2004, Marvel and Mega Bloks announced a multi-year license agreement that allowed Mega Bloks to use several Marvel superhero characters and create movie-related products. LEGO did not produce any Spider-Man or Marvel-themed sets between 2006 and late 2011.
In 2009-10, Marvel Entertainment was purchased by The Walt Disney Company, with whom LEGO had a long-standing relationship producing Disney-themed sets. In July 2011 it was announced that LEGO had obtained a license to the Marvel characters as part of an expansion of its license agreement with Disney. At about the same time, LEGO expanded its license deal with DC Comics, a subsidiary of Warner Brothers, to include the full line of DC characters. LEGO had a previous license with DC to produce Batman-themed sets, which were first released in 2006.
With licenses from these two major comic book companies in hand, LEGO created two Super Heroes themes, DC Universe Super Heroes, launched in late 2011, and Marvel Super Heroes, launched in mid 2012. Both themes are currently in production as of August 2014.