After a nearly five-hour standoff with a mountain lion in Mountain View on Tuesday night, wardens ended up trapping and tranquilizing the big cat inside the parking garage of a typically quiet Silicon Valley apartment complex.

After all the commotion, the 2-year-old male was set free on the Peninsula just before midnight, Fish and Game Lt. Andrew Hughan said.

The drama began after residents, including some children, reported seeing a mountain lion wearing a radio-type collar around its neck in the community about 6 p.m., according to Mountain View police Sgt. Saul Jaeger.

"I was skating and then I just saw the mountain lion in a garage," said Victor Lopes, a young boy. "Me and my friends started running."

People took photos and showed them to police, who realized this was the real thing.

Then, for hours, police, wardens and residents surrounded the garage of a building in the 2000 block of California Street. The scene was tense, like a "standoff," said Mountain View Police Capt. Chris Hsiung, referring to the cat cowering underneath a car in the apartment garage as everyone looked on.

Fish and Game wardens, along with police from Palo Alto, Sunnyvale and Los Altos, raced to help. All held weapons poised, ready to pull the trigger if the cat decided to attack, which it didn't.

Mountain View police asked residents to stay at home, and took to social media, creating the hashtag #MVPuma, to keep residents a blow-by-blow of what was going on.

Just about 11 p.m., Hughan said wardens tranquilized the mountain lion. Within an hour, the cat was set free somewhere in San Mateo County.

It turns out, the cat, which broke away from its mother, was being formally studied as "mountain lion 46M" and tracked by the Santa Cruz Puma Project, a study group at UC Santa Cruz and the California Dept. of Fish and Game.

Many were thankful the capture and release ended so peacefully.

"Thank you, thank you, thank you for not hurting him!" Laurel Jack wrote on Facebook. "It's not the animals fault we have invaded their territories."

NBC Bay Area's Shelby Hansen and Kristofer Noceda contributed to this report.