A knife-wielding man who was shot and killed early Sunday by Philadelphia police apparently had broken into City Hall offices and ransacked a state Supreme Court conference room.

Capt. Dan Castro of the Crime Scene Unit yesterday confirmed that handwriting of "religious rhetoric" found on Charles Kelly matched writing found in the conference room.

Kelly was also found with a cake knife and a Bible from City Council President Anna Verna's office.

"We are certain beyond a shadow of a doubt that this individual is connected to the shooting," Castro told reporters yesterday.

Police offered few details about Kelly yesterday except to say he was about 26 years old.

Police said the last hours of Kelly's life played out this way:

Sometime after 3:30 p.m. Saturday, Kelly scaled scaffolding on the south side of City Hall and broke a 5-by-10-foot window on the fourth floor.

He entered and ransacked Room 450, an ornate conference room lined with portraits of former state Supreme Court justices and tall wood-and-glass cabinets filled with law books.

After scrawling religious messages on legal pads and desk matting, Kelly walked around to the north side of City Hall and broke a window on the door to Room 405, an office for Verna's staff.

Inside, Kelly scrawled the words "Holy Bible" on a desk in pencil and then stole a Bible and a cake knife with a serrated edge, police said.

Police stationed at the one open City Hall entrance did not detect the break-ins as they were happening. Kelly was also not seen on security camera tapes.

At 2 a.m. Sunday, police were called to the Robert N.C. Nix Federal Building at 9th and Market streets, where Kelly had broken a window. Police shot Kelly first with a stun gun after he lunged at them with the knife from Verna's office while yelling, "Kill me!"

Police then shot and killed Kelly after the stun gun failed to stop his attacks. Police later found the Bible from Verna's office with Kelly's possessions.

The break-in at Verna's office was discovered at 3 p.m. Sunday. Nothing appeared to be missing at that time, and police tried to determine whether the window had been broken by accident by workers or on purpose by a vandal.

City Hall was closed Monday for Martin Luther King Jr. Day. The break-in at the state Supreme Court's conference room was discovered about 9:40 a.m. yesterday by a worker on the scaffolding outside the room.

"This frankly is an absolutely bizarre turn of events," said Capt. Ben Naish of the Police Public Affairs Unit. "A tragic turn of events occurs early Sunday morning, and only 24 hours and 48 hours later do we begin to piece together the events preceding the confrontation with police."

Verna yesterday said security in City Hall, especially after hours and on weekends, has been a "major concern" for her. She plans to speak with Mayor Street's staff about improving security.

"My main concern, however, will always be the safety of the people who work in City Hall," Verna said. "Thank God that this incident did not take place during work hours when my staff was present. Otherwise, the outcome could have been a far worse tragedy." *

Daily News staff writer Mark McDonald contributed to this report.