A train engineer saved a helpless dog who found himself trapped on Massachusetts train tracks, local news reported. Thanks to the engineer’s sharp eye and fast response, the dog avoided being hit by a train headed straight for Lowell.

“This dog had broken his cable runner when he got loose from his home that is right next to the tracks and got tangled there,” Billerica and Tewksbury Animal Control wrote in a Facebook post.

Ignacio Barillas, an engineer with Keolis, saw the dog caught on the opposite tracks as his commuter train was heading away from Lowell. He quickly remembered that another commuter train was coming towards Lowell — on the same track the dog was on.

“The dog was stuck around one of the spikes in the rails, and there was no way the dog would have been able to get out of there on its own,” Barillas told Boston.com.

After stopping the train, Barillas communicated with the dispatcher, while the train conductor and assistant conductor ran over to rescue the dog. The dog was brought onto the train and given a free ride while the train continued its route.

Upon reaching the North Billerica Station, a Billerica and Tewksbury Animal Control officer took the dog into their care. The animal control office reported that he was happily reunited with his family.

Lady Freethinker commends Barilla’s quick thinking and compassionate response to the deadly situation, inspiring us all to act with kindness and courage.