Or is this just us romanticizing the nobility? If so, when and why was this practice abandoned? Who is considered the last king to do so?
Sure, kings have not-infrequently died in battle. King Richard III was recently disinterred and then laid to rest at Leicester Cathedral; he was killed at Bosworth Field. King Harold Godwinson was killed at Hastings. Henry V very famously led his forces at Agincourt and was immortalized by Shakespeare for it.
I know a few monarchs made a point of visiting the front during the First World War, but none took any actual command of their forces. As far as I'm aware, the last time a legitimate monarch held a battlefield command was June 18, 1815, at Waterloo. However, it's possible that a Polynesian, African, or Asian king may well have been a battlefield commander more recently than that.
If you're interested in this subject, I recommend John Keegan's The Mask of Command. The first section deals with the concept of heroic - or Alexandrian - leadership, exemplified by Alexander, who led from the front in key conflicts.