The unhinged man who swung a sword around the observation deck of the Empire State Building was charged Saturday, police said.

Matthew Dixon, 35, of Lorton, Virginia, was charged with criminal possession of a weapon after being caught waving a sword that had been hidden inside a cane atop the landmark building at around 4:30 p.m. Friday, the NYPD said.

Surveillance footage of the incident posted by police shows Dixon standing on the deck holding the sword, gesturing and shouting at tourists.

He is then surrounded by cops and taken into custody.

“When an emotionally disturbed man walked into the Empire State Building holding a cane sword today, NYPD cops reacted quickly to keep people safe. Our highly-trained officers delivered a safe outcome for everyone,” tweeted NYPD Chief of Department Terence Monahan.

It wasn’t clear how he got the weapon past security.

Dixon, who police sources said was threatening to kill himself, remained at Bellevue Hospital Saturday, where he’d been taken for psychiatric evaluation.