In the first 51 years of his career in Starfleet (2242-2293), he served on a total of eleven ships, including various freighters, cruisers and starships. However, it was his nearly thirty year assignment as chief engineer aboard the USS Enterprise and USS Enterprise-A under the command of James T. Kirk that saw Scotty earn his reputation as a "miracle worker".
Following the decommissioning of the Enterprise-A, Scott decided to retire from Starfleet and set out to the Norpin V colony to quietly live out the rest of his days. Unfortunately, his transport, the USS Jenolen, was ensnared by a previously uncharted Dyson Sphere and was pulled down. Scotty managed to rig the transporter to suspend him mid-transport until rescue could arrive. Unfortunately, help did not arrive for 75 years, ironically, in the form of the USS Enterprise-D.
After spending several years acclimatizing for life in the 24th century, Scotty reactivated his Starfleet commission and began serving as the Starfleet Corps of Engineers liaison to Starfleet Command.