The beloved sea lions of Pier 39 weren’t always so beloved.

Thirty years ago, when first they hopped out of the bay and plopped on the $500-a-month yacht berths at the north end of the marina, they were pinnipeds non grata.

“At the beginning, we considered it a problem,” confessed harbormaster Sheila Chandor. “There were all sorts of suggestions of how to drive them off. Broken glass. Electricity. Bringing in a mechanical shark.”

Compassion, or common sense, prevailed. It wasn’t long before the pier’s bean counters began noticing all the people who were showing up to stare at the sea lions, and how many of them tended to drop a few bucks at pier restaurants and souvenir emporia on the way out. Before long, the sea lions were protected, adopted, revered.

With foot traffic prevailing over boat traffic, the pier proceeded to kick out the yachts from K-Dock — “We relocated them,” said pier spokeswoman Sue Muzzin — and installed three dozen wooden floats for the sea lions to rest their poor, misunderstood, blubbery bodies. This the animals proceeded to do, in overwhelming numbers. At times the sea lion population at the pier has hit four figures.

This weekend, the pier celebrates the sea lions’ 30 years at K-Dock with festivities, free tours, nature walks and a set of 30 hand-decorated sea lion sculptures intended to be sprinkled around town in the manner of the Hearts in San Francisco sculptures.

The other afternoon, the sea lions were marking the anniversary by doing pretty much what they usually do — essentially nothing. They lay motionless on their floats in the sun. Occasionally, a larger male would raise its head and bark at another sea lion to attract attention and get noticed by the opposite sex, in the way of mammals of all species, including the kind watching from the pier.

“Arp, arp, arp,” screeched a fat sea lion, shoving away a slightly less fat sea lion lest it get too close to the females it had taken a fancy to. Cell phone cameras from around the world captured every thrilling moment.

Nate Huston, from Perth, Australia, was so entranced with the sea lion disagreement that he didn’t notice a seagull that swooped down and snatched the giant pretzel out of his hand. Goodbye, three bucks.

“It’s all nature,” he said, trying to be a good sport about the pretzel since the seagull was unlikely to bring it back. “Everybody has to eat.”

Also part of nature, he said, was the smell of dozens of sea lions who take care of their toileting on the wooden pier planks, frequently without stirring themselves.

“They do stink,” Huston said. “There’s no other way to say it.”

Harbormaster Chandor said the pier employs custodians to hose off the floats and also a sea lion “ambassador,” whose primary duty is to shoo away any sea lion that tries to take up residency in areas of the marina that are occupied by rent-paying vessels.

The ambassador nudges those sea lions back into the bay with a large wooden board, having been trained in the nudging technique by sea lion behaviorists at the Marine Mammal Center in Sausalito.

Much about sea lions is a mystery. They first came to Pier 39 for the herring — not the expensive kind in the pier restaurants but the other kind which, in 1990, were having a record run. The sea lions disappeared entirely in 2009 and in 2014, probably because of low food availability, only to come back when the pickings improved.

Jennifer Cohen, a visitor from Philadelphia, said she was paying the sea lions a visit because Time magazine said it was one of the 10 things she was obliged to do in San Francisco. Her boyfriend, Tom Conroy, said the sea lions were clearly bickering about something but he couldn’t make out what they were saying.

Meanwhile, three gray seagulls were fighting in the water over the remains of Huston’s pretzel. The seagulls were not getting their pictures taken — not because it wasn’t their 30th anniversary but because nobody cares about seagulls.

Jennifer Rodriguez of Castro Valley said she came to San Francisco because there aren’t any sea lions in Castro Valley, and she planned to stay for lunch, which was probably part of Pier 39’s master plan with regard to sea lions.

Pier spokeswoman Muzzin said the pier draws 15 million visitors a year and about half of them spend quality time with the sea lions. After that, she said, sea lion fans are encouraged to stroll the pier and take advantage of such opportunities as the mirror maze ($5), giant claw game ($3), carousel ($5), pearl-in-the-oyster tank ($16), caramel apple stand ($14), flight simulator movie ($25), bungee trampoline ($10) and mini doughnut stand (6 doughnuts for $5, or 120 for $75).

“We have a lot to offer,” Muzzin said.

Steve Rubenstein is a San Francisco Chronicle staff writer. Email: srubenstein@sfchronicle.com Twitter: @SteveRubeSF

Sea lion party Pier 39 celebrates 30 years of sea lions from Friday through Monday with free sea lion discovery walks at noon, 1, 2 and 3 p.m., and free hot chocolate. The pier Sea Lion Center is hosting sea lion programs. Thirty colorful sea lion sculptures are on display around the pier.