A United States man who scaled an iron security fence in the middle of the night, eluded police and used beer bottles filled with petrol to ignite the Pennsylvania governor’s mansion has pleaded guilty to attempted murder and other charges.

On Tuesday, Cody Balmer, 38, also entered pleas for “terrorism”, 22 counts of arson, aggravated arson, burglary, aggravated assault of Governor Josh Shapiro, 21 counts of reckless endangerment, and loitering.

He is accused of the April 13 arson attack that did millions of dollars in damage to the state-owned brick building. Under a plea deal, Balmer was sentenced to 25 to 50 years in prison.

Shapiro and members of his family had to be awakened and evacuated, but no one was injured. The multiple arson and endangerment charges reflected the number of people in the residence at the time, including the governor’s family, guests and state troopers.

The fire was set hours after they celebrated the Jewish holiday of Passover with a Seder meal in the governor’s residence. Prosecutors played video clips that showed Molotov cocktails going off and a figure inside and outside the residence around the time of the attack.

Judge Deborah Curcillo called the video “horrific” and “very frightening”.

Pennsylvania Governor Josh Shapiro was the target of the arson attack, according to prosecutors [Matt Rourke/AP Photo]

Balmer told police he planned to beat Shapiro with a small sledgehammer if he had encountered him after breaking into the building, according to court documents. Balmer turned himself in the next afternoon to face charges of attempted homicide, “terrorism”, aggravated arson and aggravated assault.

Police say Balmer broke in through the southern wing of the residence, into a room often used to entertain crowds and display art. Investigators recovered two broken glass beer bottles containing petrol. The fire charred walls, tables, buffet serving dishes, plates and a piano. Window panes and brick around doors and windows were also damaged.

Shapiro’s Jewish faith and the attack during the Passover weekend raised questions about Balmer’s motivation, but Balmer told The Associated Press in a May letter from jail that religion had not been a factor in his decision.

“He can be Jewish, Muslim, or a purple people eater for all I care and as long as he leaves me and mine alone,” Balmer wrote.

He said in a brief June 9 video interview from Camp Hill State Prison that he did think beforehand about whether children might be injured.

“Does anyone ever consider children?” Balmer said in June. “It doesn’t seem that way. I sure as hell did. I’m glad no one got hurt.”

Asked why he felt Shapiro had somehow done him wrong, Balmer replied: “I’m not going to answer that.”

Balmer’s mother said days after his arrest that she had tried to get him assistance for mental health issues, but “nobody would help”. Court proceedings had been delayed while he received mental health treatment, his lawyer has said.

At a court hearing a few days after the fire, Balmer told a judge he was an unemployed welder with no income or savings and “a lot of children”.

The residence, built in 1968, did not have sprinklers. Work to fix the damage and to bolster its security features continues.