A Massachusetts man was arrested after allegedly fleeing from a hospital while undressed and attacking a homeowner with a hammer during a break-in attempt.

Newburyport Police arrested Robert J. Girard, 26, of Amesbury, after a report of a "walk-away" patient from Anna Jacques Hospital late Thursday night.

Girard allegedly fled from the hospital after removing his IVs and a GPS-monitoring ankle bracelet.

About three hours later, officers responded to a call about a man breaking into a home just a few feet from the hospital and attacking a homeowner with a hammer.

Police found Girard on Lois Street, still undressed, and arrested him.

The victim in the assault, Patrick Chamberlin, 50, of Newburyport, was transported to Anna Jacques Hospital, and was treated and released Friday.

The police report described the incident from inside the home.

“He got out of bed and a man was standing in his bedroom with a hammer, the report said. "He said the man told him, ‘I don’t want to do this!’ and Patrick told him he did not have to."

Chamberlin said he was struck with the hammer at least twice before fighting off the attacker and chasing him downstairs. He fled through the unlocked basement door through which he broke in.

"My son heard some noises and the dog barked a couple of times," Chamberlin said. "So we got up and we looked up, and there and we’re like, 'OK, something’s going on up there.'"

“When this patient fled our emergency room, we followed our policy and procedure and immediately notified the police, and worked with them to help locate the individual," the hospital said in a statement.

Girard was charged with attempted murder, assault and battery with a dangerous weapon and aggravated burglary. He was also held on a probation warrant.