Megatron effectively had his heart/soul ripped out, then his body dumped at the deepest ocean trench so that his remains could be crushed by a bazillion megatonnes of pressure. Yet some Decepticons managed to casually swim down there, stick a Cosmic MacGuffin(TM) in his chest, and hey presto - he just gets up and flies into space, good to go.Optimus Prime had the same thing happen, then he was resurrected by another MacGuffin(TM) (now in powder form!) in a sock. I cannot think of a way that Megatron can be resurrected in a way that just doesn't seem totally contrived.
Optimus Prime: "Megatron, you're back! But... how?"
Megatron: "A wizard did it."