E. Gadd's Time Machine
From the Super Mario Wiki
E. Gadd's time machine was invented by Professor E. Gadd in Mario & Luigi: Partners in Time, during the events of its predecessor. Not much has been explained how it works, other than it is powered by a magnificent gem called the Cobalt Star; and moves through time by opening time holes.
During its showcasing at Peach's Castle, the princess used it, along with Toadiko and Toadbert, to visit the Mushroom Kingdom's distant past. She unfortunately came into the time in which the kingdom was invaded by the Shroobs. The Cobalt Star was then destroyed in order to trap the Elder Princess Shroob, and with a last bit of energy, a Junior Shrooboid transported back to the present, wrecking the time machine and rendering it useless. The time machine's return, however, temporally opened a time hole in the castle garden, allowing Mario and Luigi to step back into the past Mushroom Kingdom. The time machine was later re-engineered to run off of the energy illuminating from the numerous time holes in the castle, allowing the Mario brothers to safely return to the present. The last use of the time machine was by Baby Mario, Baby Luigi, Baby Peach, and the younger Toadsworth in their farewell back to the restored past.