It was an admirable speech, and so on, but that's not what interests me. Instead let's consider beginnings and endings.
Beginnings. You can usually see the "light" or "droll" touches in speeches like this coming from miles away. Therefore they are usually met with obligatory polite laughter, masking the inner groans. The second and third jokes Obama made at the opening of the speech were from this proud tradition:
Of course, all relationships have their ups and downs. Admittedly, ours got off on the wrong foot with a small scrape about tea and taxes. (Laughter.) There may also have been some hurt feelings when the White House was set on fire during the War of 1812. (Laughter.)
Hardee-har! When an American President visits the UK, there has to be a "light" remark of this sort about those early "unfortunate misunderstandings" and that time the Brits burned the White House down.
But the first joke he told was genuinely funny, because in the circumstances it was genuinely daring:
I have known few greater honors than the opportunity to address the Mother of Parliaments at Westminster Hall. I am told that the last three speakers here have been the Pope, Her Majesty the Queen, and Nelson Mandela -- which is either a very high bar or the beginning of a very funny joke. (Laughter.)
Daring? Yes. The day after having dinner with the Queen, when addressing the Parliament of which she is nominal supreme leader, to raise in everyone's mind the image of a joke starting, "the Queen, the Pope, and Nelson Mandela walk into a bar..." was a risk. Obama's straight-arrow bearing increases the incongruity and therefore the power of the joke. (Imagine George W. Bush telling it.) I would love to have heard the discussions about whether it was a "seemly" thing to say, in that setting. Glad they used it, because it worked.