It was sunny and clear Friday morning and the water was calm off the coast of Provincetown, Massachusetts, where Michael Packard was diving for lobsters.

His longtime fishing partner Josiah Mayo followed him in their J&J fishing vessel, chasing him through the bubbles that rose from Mr. Packard’s breathing equipment.

The men had already caught 100 pounds of lobster, and Mr. Packard was about four feet under the water looking for more.

Suddenly the bubbles stopped, said Mr. Mayo. Then the water began to swirl violently. A creature broke the surface and for an excruciating split second, Mr. Mayo thought it was a great white shark.

“I immediately thought it was the shark encounter that we had unfortunately been preparing for years,” he said in an interview on Saturday.

Then he saw the fluke and the head of a whale. Moments later he saw Mr. Packard fly out of the water.

“‘It tried to eat me,'” Mr. Packard stuttered, according to Mr. Mayo. The whale, a humpback whale, swam away as Mr. Mayo and another fisherman helped Mr. Packard back into the boat.

According to Charles Mayo, Josiah Mayo’s father and senior researcher at the Center for Coastal Studies in Provincetown, a town of about 3,000 at the tip of Cape Cod, such terrifying encounters are virtually unknown. There is an account of a woman who was torn down by a pilot whale. There are reports of sperm whales going on the offensive after the harpoon. And in 1896 the New York Times reported the incredible story of a whaler found in the belly of a whale and rescued alive in October 1891.

“I’ve never heard of it,” said Dr. Mayo on Mr. Packard’s ordeal. Nevertheless, the encounter can be explained, he said.

The whale, possibly a 32 to 35 foot cub that had previously seen swimming in the area, was most likely diving for food when it accidentally caught Mr. Packard in its huge mouth.

Humpback whales spend much of their time in this part of New England foraging and devouring small schooling fish, said Jooke Robbins, director of the humpback whale study program at the Center for Coastal Studies.

They rush quickly, open their mouths, and use whiskers to filter out the water before swallowing the fish, said Dr. Robbins in a statement.

When the whale realized it had caught something that wasn’t its typical prey – in this case an unsuspecting lobster fisherman – it reacted like a human who accidentally swallowed a fly, said Dr. Mayo.

“We definitely don’t eat anymore,” he said. “We spat out the food and some of us left the restaurant.”

Reports of Mr. Packard’s ordeal caught Twitter on Friday. That afternoon, Mr. Packard told reporters that on his second dive, he was at the bottom of the ocean when he felt “that truck hit me.”

His first thought was that a great white shark had attacked him, but when he didn’t feel his teeth piercing him, he realized he was inside a whale.

“I was completely inside; it was completely black, ”Mr. Packard told the Cape Cod Times. “I thought to myself: There is no way I can get out of here – I’m done, I’m dead. I could only think of my boys – they’re 12 and 15 years old.”

Mr. Packard said he had been in his mouth for at least 30 seconds, wondering if he would run out of air or be swallowed. He said he fought the whale’s mouth and could feel its powerful muscles pressing against him. Then he saw light and felt the whale’s head trembling and its body being thrown into the water.

Mr Mayo said he called 911 and an ambulance picked her up at the dock. Then he called Mr. Packard’s wife.

“‘Hello Mike is fine'” Mr. Mayo recalled telling her. “You have to lead with that.”

Mr. Packard, who was discharged from the hospital on Friday, had extensive bruises but no broken bones.

On Friday afternoon he posted a happy message on a Provincetown Community Facebook page thanking the Provincetown Rescue Team for help.

“I was lobster diving and a humpback whale tried to eat me,” he wrote. “I was in his closed mouth for about 30 to 40 seconds before he surfaced and spat me out. I have very bruises, but no broken bones. “

Mr. Mayo said he initially thought Mr. Packard had broken his leg. Although he was afraid for his friend, he said he was a little relieved that the season might be over.

But when he learned that Mr. Packard had not suffered any broken bones, Mr. Mayo said he knew the two would be leaving soon.

Mr. Packard promised the reporters the same thing.

He said, “As soon as I’m healthy I’ll be back in the water.”

Jack Begg contributed to the research.