Humpbacks have put on a show this summer inside and outside the Golden Gate — flopping around, waving their flukes and leaping out of the water — a bonanza for whale watchers in tour boats and on dry land that scientists say will remain a regular thing.

The ballet of the behemoths, far from a one-time event, is the result of the humpbacks recovering from near-extinction thanks to an international whaling ban, intense conservation and protection of their breeding grounds.

John Calambokidis, a senior research biologist for the nonprofit Cascadia Research Collective, said the giant cetaceans are swimming off the coast of California in numbers equal to their historic population and extending their range into places where they lived long ago.

“Their numbers reached carrying capacity in the last five years, and that’s when sightings in unusual areas began to occur,” said Calambokidis, who has been studying humpback and blue whales for 35 years.

“It’s a good thing in the sense that it reflects the recovery of humpback whales,” he said. “It’s a bad thing in that some of these coastal areas they are repopulating, like San Francisco Bay, put them in greater conflict with other activities, like noise, ships and recreational boaters.”

Since May, large pods have moved through Monterey Bay, past Pacifica and just beyond the breakers at Stinson Beach. Lucky viewers have spotted humpbacks doing pirouettes and splashing down under the Golden Gate Bridge, near the Channel Islands in Southern California and in Puget Sound in Washington.

The phenomenon is all the more remarkable after record-high temperatures in the Pacific Ocean two years ago unleashed toxic algae that closed down the Dungeness crab fishery and contributed to a huge death toll among seabirds and sea lions.

Peter Winch, a naturalist with the Oceanic Society conservation group, said whales have been especially visible this year because cold ocean upwellings have sprinkled near-shore waters with plankton. The whales swim close to shore for anchovies, which feed on plankton, he said.

“They are taking advantage of anchovy shoals that are numerous around the coast,” Winch said. “The humpbacks have the ability to pick and choose. They can stay out in deeper water and eat krill or they can come in. In the last few years, they have just really clued in on this abundance of anchovies.”

Humpbacks, which have long pectoral fins and distinctive knobby heads, are unique among baleen whales. They are friendly and playful, often interacting with other species, including bottlenose dolphins and right whales, and they have complex vocalizations that sound like singing.

They are known for their acrobatic breaching, in which they lift nearly their entire bodies out of the water before splashing down.

The whales, which can grow to 52 feet long and almost 80,000 pounds, were hunted throughout the 18th and 19th centuries in both the Atlantic and Pacific oceans, reducing the global population by more than 90 percent.

Before 1900, an estimated 15,000 to 20,000 humpbacks lived in the North Pacific. Only about 500 remained in 1966, when the International Whaling Commission finally halted the killing.

Calambokidis said humpback numbers have increased by 7 to 8 percent every year since he began studying them in the 1980s. At least 40,000 of the creatures now live in the world’s oceans — and the North Pacific population is at a historic high.

They have done so well, in fact, that nine of the 14 subspecies that had been listed under the Endangered Species Act since 1970 were taken off the list in 2016 in what one federal official called a “true ecological success story.”

Bay Area residents have been particularly enamored with the species since 1985, when a 40-ton humpback named Humphrey swam through the Carquinez Strait, up the Sacramento River and into a creek near Rio Vista. The Solano County city became the focal point of a whale craze, attracting 10,000 people a day as experts tried desperately to turn around the lost animal — which went back to sea after 25 days.

The local humpbacks migrate along the California coast past San Francisco on their way to and from their breeding grounds in Mexico and Central America. Unlike gray whales, which generally make a beeline to Alaska, humpbacks move north slowly after giving birth, feeding all along their migration route.

Jared Davis, the captain of the Salty Lady fishing and tour boat, said he and his passengers spotted 50 humpbacks on a trip from San Francisco to the Farralon Islands last month. Boaters there have also seen blue whales, fin whales, orcas, dolphins and porpoises in large numbers this summer.

“When the conditions are good, the whales flourish, and the conditions have been good the last couple of years,” said Davis, who takes people whale watching on the weekend and salmon fishing during the week. “It’s a lot of fun.”

The problem with humpbacks moving close to shore, Calambokidis said, is that boats can hit them or crab pot lines can tangle them up.

A recent study by Point Blue Conservation Science found that ships strike and kill an average of 22 humpbacks a year off the coast of California, Oregon and Washington. About 7,300 vessels pass the Golden Gate every year.

The number of whales entangled in fishing lines off the West Coast has risen sharply in recent years, with 71 cases in 2016 — up from 57 the year before and the most since the National Marine Fisheries Service began keeping records in 1982.

“There has been a dramatic increase in entanglements, particularly in crab pots,” Calambokidis said. The humpbacks, he said, “are arriving earlier in the spring to find prey and feed and that overlaps with the crab fishery.”

Another long-term threat to the whale resurgence is climate change, though all signs indicate the humpbacks will be back again next year in all their glory.

“It’s not unusual anymore,” Calambokidis said. “Sometimes they will be seen closer to shore because prey is closer to shore and sometimes offshore because the prey is out farther to sea, but humpback sightings will be much more common going forward.”

Peter Fimrite is a San Francisco Chronicle staff writer. Email: pfimrite@sfchronicle.com Twitter: @pfimrite