The drama began unfolding in the suburb of Rinkeby at round 4.15am on Tuesday.
"We received a call that a man armed with a knife, revealed himself in a stairwell and then disappeared into an apartment," Lars Byström, a spokesperson for Stockholm police, told the TT news agency.
The apartment building where the armed man is. Photo: Jessica Gow/TT
Police denied initial reports in Swedish media that there was a woman and a child inside the building, which was surrounded by officers and paramedics.
They later confirmed that there was an older relative in the apartment with the knifeman, who were refusing to let his relative leave.
Police spokesperson Albin Näverberg told the TT newswire that the man was believed to be "psychologically unstable" but not dangerous. He said police were negotiating with the man and were trying to avoid using force.
But by 5pm police confirmed the siege-like situation had ended and the pair had left the apartment. Both were set to be questioned by officers.
Rinkeby is situated in north-western Stockholm. It is a low income area and is one of the suburbs where riots broke out in 2010, sparking global headlines.