Fred was killed in an explosion probably created by Augustus Rookwood.
Fred was killed by a Blasting Curse from the grounds that blew a hole in the Hogwarts Castle wall next to him. Percy, Ron, Harry and Hermione were there and survived the blast, though Harry's head was bleeding. Shortly after, Rookwood, a Death Eater who had worked at and spied at the Ministry, came running by chasing Hogwarts students. Percy, in a rage over Fred's death, shouted,"ROOKWOOD!" and chased after him.
Fred was killed by a huge fart that blew up hogwarts