A high-speed chase that wound 40 miles through towns in New Hampshire and Maine on Wednesday ended in Lebanon when a Maine State Police cruiser hit the fleeing vehicle, causing it to spin out.

The driver and passenger in the vehicle being chased were not injured. The driver, Charles Bill, 33, of School Street in Berwick, was taken to York County Jail in Alfred, where he was charged with eluding police and on multiple outstanding warrants, police said. He also was charged with aggravated drug trafficking when he allegedly tried to hide 40 grams of heroin in a body cavity prior to being booked into York County Jail.

The chase started in New Hampshire when Somersworth police tried to stop a 2002 Mitsubishi Gallant. The car did not stop and Somersworth police called ahead to Berwick police asking them to pick up the chase.

The car continued into Lebanon and Milton, New Hampshire, before returning to Maine, police said.

A state trooper used his cruiser to cause the driver of the fleeing car to lose control on Heath Road in Berwick.