If you need that experience to level up, and the monster is still alive, then I would guess the answer to be no. You would have to fully kill the monster.
If you already have 5 experience points waiting on the side, and you rolled a 20 in the middle of a battle, then yes - you can level up during a fight.
Rules state any time you roll a 20 for whatever means, that is your chance to level up!
This is the one to go on.
You don't have to kill the monster when the 20 is rolled. You simply have to roll the natural 20 during an attack AND have 5 experience to spend to level up.