Perseus slew the Gorgon Medusa because King Polydectes set him this challenge, and if he failed, then the king would marry Perseus' mother Danae.