BOSTON, Massachusetts — A planned three-hour whale-watching cruise off the Massachusetts coast turned into an all-night affair for 163 people aboard a boat that limped back into Boston Harbor on Tuesday morning.

The passengers and crew of the Boston Harbor Cruises boat Cetacea spent the night stranded off the coast of Nanhat, Massachusetts, about 8 miles north of Boston, after the boat’s propeller snagged on a cable, said Sheila Green, a spokeswoman for the company that operated the tour.

The vessel docked in Boston at 7:30 a.m. on Tuesday, after about 18 hours on the water, she said.

“Everybody got off without incident,” Green said.

The boat, carrying 157 passengers and a crew of six, had departed at 1:30 p.m. on Monday from Boston Long Wharf, a popular pier where sailboats, ferries and motorboats launch out into Boston Harbor.

Two-and-a-half hours later, the boat’s propeller caught on a 7-inch thick cable, called a messenger line, in the water near Nahant, said Green.

Three Coast Guard crews, including medical personnel, responded to the incident at about 4:30 p.m., and the two Coast Guard ships remained at the stranded boat’s side through the night, according to a Coast Guard statement.

Scuba divers cut the entangled cable and freed the ship early Tuesday, and the boat returned to Boston Wharf on its own power, Green said.

All passengers of the ill-fated tour will be given a refund, $500 in cash, and a $100 gift card to Boston Harbor Cruises, Green said.