I am trying to close bootstrap popover using <kbd>ESC</kbd> key press.

But it does not seem to be working when using:

<!-- language: lang-js -->
$(document).keyup(function (event) {
    if (event.which === 27) {
        $('#example').popover('hide');
    }
});         

Here is the fiddle with bootstrap popover:

http://jsfiddle.net/mashinista/b2NKt/

The fiddle you included has the popover code, but not the escape code.

Add it and, as koala_dev pointed out, you should be fine:

Demo in fiddle

<!-- language: lang-js -->
$('#example').popover();

$(document).keyup(function (event) {
    if (event.which === 27) {
        $('#example').popover('hide');
    }
});

Also, this is very similar to how the modal escape function works