In a city of millions of keys, this is a story of two of them. Two keys carried by two strangers that opened the same apartment door. Twice, the police said, one man let himself inside while the other was away. The first time, the victim was just that — a victim. The second time, he was ready.


The tenant, a college professor of technology, had moved into the apartment in April. It was a quiet walk-up on East 11th Street in Manhattan. The superintendent told the professor, Mr. Lee, that the lock had just been changed.


Two months later, on June 12, someone entered the apartment while Mr. Lee, who did not want his full name disclosed, was at work. The burglar stole two video game consoles and other electronics. There was no sign of forced entry, nor any witnesses.


“I decided to be more defensive,” he said.


The technology professor tried a couple of surveillance cameras before settling on one made by Dropcam. He placed it in a room where he kept electronic valuables, and set it to constantly record, with the last seven days of video stored online.


The view offered a glimpse into a bachelor’s pad. The room was messy, not really unpacked. There was a chin-up bar mounted in the door frame and a guitar leaning in the corner, near a microphone on a stand. “I play guitar with my church,” he said.


On Monday, seven weeks after the burglary, at 3:35 p.m., Mr. Lee’s apartment door opened. The camera recorded a man poking his head into the door, then entering.


He was young and well put together, with stylish eyeglass frames and a recent haircut. He wore cargo shorts and a Guinness T-shirt and purple gloves and Nikes and a backpack, and looked like a bike messenger or student or the sort of guy that shows up in the East Village in packs of 12 for happy hour and brunch. If it was a disguise, it was inspired.


The burglar left the way he came, having taken an iPad, a watch and a wallet filled with old, canceled credit cards.


Mr. Lee arrived home and noticed something missing, and quickly logged onto the camera’s video, finding a little red flag at the 3:35 p.m. mark, meaning motion had been detected then. He watched and called the police.


A lot of surveillance video in New York City is shot from a low-resolution camera mounted on a light pole in the dark. By those standards, Mr. Lee’s high-definition video was Oscar-worthy in its framing and lighting and the detail of the suspect.


“The police saw the video and thought it was hilarious,” he said. “They said it’s very rare for a private citizen to have surveillance video in their apartment.” The police released the video to newspapers and television stations, and Mr. Lee tacked up a homemade flier in a nearby bar.


Someone who saw the video called the police, and three days after the burglary, the police arrested a suspect, Piotr Pasciak, 24, of Greenpoint, Brooklyn. A tour of his Facebook page suggests that the hipster look was no disguise. In photograph after photograph, Mr. Pasciak, who had 682 friends as of Friday, can be seen, hair mussed, gazing at himself in a mirror or drinking a bottle of Heineken or a red beverage in a martini glass.


The cheery pictures and posts peter out in 2009. That is because Mr. Pasciak was in prison at the time after pleading guilty to charges stemming from three home-invasion burglaries in Ostego County, in which guns and stereo equipment were stolen. Mr. Pasciak pleaded guilty to attempted burglary, a lesser charge.


“Pete, keep your head up,” a friend wrote on his Facebook wall in 2010. “You will be out soon.” He was released in January 2011.


Over the last few days, people wrote on his wall asking why his phone was not working. His mother, Malgorzata Pasciak, wrote, “Peter where r u call me.”


The police charged him with burglary in both break-ins at Mr. Lee’s apartment. His mother defended him in a telephone interview on Friday. “He’s a good guy, and I don’t know if that’s him or not,” she said, referring to the burglary video. It was unclear Friday how he could have had a key.


The superintendent, who gave only his first name, Jack, said on Thursday that it was his custom, after a tenant moved out, to remove the lock and toss it in a box of similar locks, replacing it with another from the box. Had he, in April, removed the old lock and inadvertently put it right back in? He wasn’t sure anymore, he said. He did not recognize Mr. Pasciak.


Mr. Lee said there was a brand new lock on his door now. And, in his pocket, he carries the only key.