Mantle material is heated near the Earth's core. Its heat makes it less dense at so it begins to rise. As it rises it cools, by the time it reaches the crust it is dense enough to sink again. This causes a cycling of mantle material called mantle convection.
The crust pulls magma towards it via magnetic atraction. When the magma reaches the crust it begins to be repelled and sinks again.