Why did william of Normandy become king?

William of Normandy was related to the king of England and was next in line for the throne when the king died instead of him another person became king and seeking revenge he led an attack on England and won.