Anchorage, Alaska • A powerful undersea earthquake sent Alaskans fumbling for suitcases and racing to evacuation centers in the middle of the night after a cellphone alert early Tuesday warned that a tsunami could smash into the state’s southern coast and western Canada.

The killer wave never materialized, but people endured several tense hours in shelters, waiting for a potential catastrophe that they feared could wipe away their communities at any moment.

The magnitude 7.9 quake in the Gulf of Alaska triggered the jarring alert that awoke people shortly after midnight. Fleeing motorists sometimes clogged the only highway out of their towns in the rush to get to higher ground. Many took refuge at schools and other shelters.

For Alaskans accustomed to tsunami threats and regular tsunami drills, the warning still created some fretful moments. The phone message read: “Emergency Alert. Tsunami danger on the coast. Go to high ground or move inland.”

Keith Perkins got the phone alert and later heard sirens going off in his hometown of Sitka. He said people on Facebook were talking about whether the threat was real and what they should do.

Given the magnitude of the earthquake, Perkins said, he thought it best to head to the high school, a tsunami evacuation point, even though in the past he felt his home was probably high enough.

“I figured I’d probably just better play it safe,” he said.

Hours later, the warning was canceled and people returned home for an hour or two before the workday began.

There were no reports of damage, not even on Kodiak Island, the closest land to the epicenter. But people reported on social media that the shaking was felt hundreds of miles away, in Anchorage, the state’s largest city, which was not under a tsunami threat.

Eleanor King in Kodiak was jolted awake by the earthquake, which she said felt similar to Alaska’s 1964 magnitude 9.2 earthquake — the strongest on record in North America. That quake generated tsunamis that claimed about 130 lives as far south as California.

“It started out just like the big one,” King said of Tuesday’s quake. “It was very slow and rolling. … That’s what scared us.”

At the diner she runs, King permitted a little levity after the all-clear was sounded. King’s Diner invited people to breakfast on its website: “Hungry? Tsunami got you up early.”

By the time, her customers started arriving, the excitement had passed, and people quietly ate their meals, speaking little of the quake.

The quake was recorded at 12:32 a.m. in the Pacific Ocean about 170 miles southeast of Kodiak, home to one of the nation’s largest Coast Guard bases. Kodiak is about 200 miles south of Anchorage.

The temblor prompted a warning that spanned thousands of miles of Alaska’s southern coast, from Attu in the Aleutian Islands to Canada’s border with Washington state.

In parts of British Columbia, officials banged on doors to rouse people from their sleep.

“I just heard the firetrucks going around, honking their horns and on the loud speaker saying there is a tsunami warning,” said Gillian Der, a geography student at the University of British Columbia. “It was very apocalyptic.”

Elsewhere in the U.S., Washington state, Oregon, California and Hawaii were under tsunami watches. Officials in Japan say there was no tsunami threat there.

Reports varied about how long the shaking lasted, depending on location.

In the popular cruise-ship town of Seward, about 110 miles south of Anchorage, Fire Chief Eddie Athey said the quake felt like a gentle rattle that lasted for up to 90 seconds.

“It went on long enough that you start thinking to yourself, ‘Boy, I hope this stops soon because it’s just getting worse,’” Athey said.

The earthquake woke Kodiak Police Lt. Tim Putney from a dead sleep. He said it shook for at least 30 seconds but acknowledged that his estimate might be skewed by sleeping through some of it.

“I’ve been in Kodiak for 19 years. That was the strongest, longest-lasting one I’ve ever felt,” he said by telephone.

The Alaska Earthquake Information Center categorized the shaking as light.

John Bellini, a geophysicist with the U.S. Geological Survey’s National Earthquake Information Center, said there had been more than two dozen aftershocks as of about 6:30 a.m. The biggest had a magnitude of 5.3.

The earthquake was initially reported as magnitude 8.2, but better calculations can be made as more data comes in, Bellini said.

Larry LeDoux, superintendent of the Kodiak Island Borough School District, estimated that 500 people took shelter at the high school. He described the atmosphere inside as calm, with people waiting for updates.

In Seward, at the southern end of Alaska’s Kenai Peninsula, residents retreated to higher ground or left on the only road out of the city, the fire chief said. He described it as a controlled evacuation similar to people driving home from a holiday fireworks show.