A Maine preschool teacher is being credited with saving the lives of about two-dozen children after the driver of the bus they were on suffered a heart attack at the wheel.

Joshua Galvin, a teacher at Toddle Inn Child Care in South Portland, was accompanying 25 children, all 4 and 5 years old, on a trip Wednesday when the driver of their private bus passed out, according to the Scarborough Police Department. The driver's foot was on the gas pedal when he lost consciousness.

Galvin realized what happened and hurriedly brought the bus under control, police said. He was able to stop it safely and remove the key from the ignition.

The driver, who has not been identified publicly, was taken to a hospital, where he underwent surgery to place a pacemaker in his chest, police said. He was expected to recover.

"Due to Galvin's quick thinking and actions, no one was seriously injured," the department said in a statement on its Facebook page. "The outcome of this call could have been much worse if not for Galvin."

Parents of children at Toddle Inn praised Galvin for his actions.

“My son’s preschool teacher,” a woman wrote. “We are so lucky to have Josh and the other Toddle Inn staff caring for our kids!”

“Mr. Josh was already a gift to our children, and an amazing, funny and compassionate teacher. And now, truly a hero as well,” another woman wrote. “Amazing!”

A grandmother described Galvin as a “very special” member of the child care center’s family.

“My granddaughter loves him,” she wrote. “She was in the van and is safe thanks to his quick thinking.”

Galvin was presented with a Scarborough Police Department challenge coin on Thursday. A challenge coin, which is typically seen in the military or law enforcement, is a coin bearing an organization or agency’s logo or insignia and is carried by its members.

Members who meet up with one another will sometimes “challenge” one another to see if everyone is carrying their coins.