I have not heard of a cruise line excursion where the length of time as described doesn't mean from departure from the ship to return to the ship. So a 9 hour tour might depart the ship at 8am, returning at 5pm. We don't know what time you are in Livorno, but I would expect a 9 hour tour to be one of the first one off the ship.
Trains are pretty reliable, to very reliable in most all of Europe. However, in a day where you have limited time in a port, arriving for and waiting for trains eats into your touring times. So, while trains are a very good way to tour, for a more complicated excursion like this ship's excursion, or much more efficiently, a private excursion, is probably the way to go in your situation.