BROOKLINE — The bear found in a towering pine tree in the yard of a multimillion-dollar home here today is the same male bear who rambled across Cape Cod before being captured two weeks ago and then exiled to Central Massachusetts, state officials said.

After being captured and relocated on June 11, the stubborn bear trekked 100 miles eastward before ending up at around 7:30 a.m. in the backyard of a $4.9 million home on Pine Road, officials said.

Officials said the bear, one of an estimated 4,000 in the state, embarked on his odyssey in an effort to establish his own territory. The bear weighs about 180 pounds and is about 2½ years old. He is being taken back to the countryside today — this time he’ll be released farther from Boston than before.

But officials said they could not guarantee that he would stay put.

“This could happen again,’’ Tom O’Shea, assistant director of the Massachusetts Division of Fisheries and Wildlife, said at a news conference in Westborough. “We do know that bears are extending their range eastward.’’

Added Environmental Police Major Wil Gray: “As a matter of course, bears are moving east, and we have to, as a populace, learn to live with the bears … and perhaps change some of our habits so we can coexist more harmoniously.”

The unnamed bear’s eastward journey ended in the branches of a white pine tree on the grounds of Alan and Sherry Leventhal’s home.

Sherry Leventhal said she was deeply skeptical when police showed up and told her that the bear had settled in on her property. “Police told me, ‘There’s a bear in your yard,’” she said. “I didn’t believe them.’’

She said wild animals are not unknown to her. “I’ve seen wild turkeys. We’ve had a fox once,’’ she said. “But never a bear.’’

Leventhal added: “I had breakfast watching the bear out my front window, which was quite a freaky experience.”

“I don’t think the rest of my life will be as exciting as this morning,” she said.

Brookline police said a bear had been spotted on Monday night in the same area of town.

Police Chief Daniel O’Leary said officers could not locate the animal Monday, so they made a plan to flood the area with officers early on Tuesday morning to search for the wandering bruin. He was located at Pine Road, and police alerted the public via their Twitter account.

On their official Twitter page, Brookline police posted photographs of the bear underneath their rewrite of a classic children’s book line.

“Black bear, black bear, what do you see? I see Brookline police, looking at me.’’

After 9 a.m. today, an Environmental Police officer, operating from a cherry picker, shot the bear with a tranquilizer dart when the animal was an estimated 50 feet up the tree. After being shot, the animal climbed an estimated 30 feet higher. But once the drug took effect, the bear tumbled to the ground.

O’Leary said the bear’s fall was broken by tree branches and that he landed on bushes.

Onlookers came from every age group, including a cluster of small children gathered around their mother and adults who seemed to relish the chance to shout out one-liners to the crowd.

As the cherry picker with the armed man on board rose upward, one child was heard asking, “How big is the needle?” And when the bear appeared to have escaped the dragnet set up for him, a father nearby shouted, “He’s smarter than the average bear!’’

The peripatetic animal had been spotted in numerous Cape towns since May 27 and is believed to have swum across the Cape Cod Canal, state wildlife officials said. After being tranquilized and moved to Central Massachusetts, biologists placed a tag on the bear’s ear for identification purposes, officials said.

That tag was how he was identified today.

Once the bear was on the ground, O’Leary, officials gave it a second tranquilizer shot before the animal was placed in 480 pounds of ice shavings picked up from Brookline Ice and Coal.

When a bear is tranquilized, its body temperature rises and that may endanger the animal’s health, said Reggie Zimmerman, spokesman for the Massachusetts Executive Office of Energy and Environmental Affairs.

The shaved ice is used “to cool the body temperature of the bear for transport,” he said. The animal was placed in a truck.

Douglas Chope, 48, said he saw roughly 100 people near his Pine Road home, gazing upward.

“Pretty-good sized bear,’’ Chope said. “We’ve had deer, we’ve had coyote, and supposedly someone saw a wolf at some point. But obviously never a bear.”

While many of those gathered were public safety officials, most appeared to be curious citizens, Chope said.