The rivalry traces back to the console wars between Sega and Nintendo. Nintendo's Mario had dominated the industry for years, so Sega's answer was to create its own mascot, Sonic the Hedgehog, whose popularity boosted the company's sales dramatically.
Sega's strategy was to release as many Sonic titles as possible to compete, and in time the two mascots became known as gaming's ultimate rivals. Despite the competition, they're actually friendly toward one another, each aware of the other's strengths and weaknesses and full of mutual respect.