The man who scaled the perimeter wall of Buckingham Palace before "admiring" the gardens for 10 minutes is a convicted murderer.
Dennis Hennessy cut his right hand as he climbed over the top of the wall, which is between 2.4m-3m high, and set the alarm off on Wednesday night (local time).
He then walked around the gardens for around 10 minutes towards the palace, where the Queen was in residence with the Duke of Edinburgh and the Duke of York, before being arrested by armed police.
As he was detained, he asked "is Ma'am in?" repeatedly, prosecutor Tom Nicholson told Westminster Magistrates' Court on Friday.
In interview he told police he had "walked through the gardens admiring the view".
The court heard he was on licence after being convicted of the murder of a homeless man in 1992.
Hennessy, 41, pleaded guilty to one count of trespass on a protected site and one count of criminal damage.
Chief magistrate Howard Riddle sentenced him to four months for trespassing and two months, to run concurrently, for damaging the wires of the alarm system.
"I am content that our security measures worked effectively on this occasion and at no time was any individual at risk," said Commander Adrian Usher, head of London police's Royalty and Specialist Protection unit.
Neither the police nor Buckingham Palace would confirm whether members of the royal family were at the palace but it is believed the Queen was at the residence at the time having carried out the state opening of parliament hours earlier.
A spokesman for the Queen said they did not comment on security issues.
One of the biggest security breaches at Buckingham Palace happened in 1982 when an intruder, Michael Fagan, climbed a wall and wandered into a room where the Queen was in bed.
PAA / Reuters