To be on one's last legs means to be worn out, tired, run down, and ready to die or otherwise cease working. Some examples I've found are
Grandfather is on his last legs. He'll be on his way to Heaven soon.
I just ran a mile to tell you this; I can't walk up the steps. I'm on my last legs.
My car is on its last legs. I doubt it will get me down the street to the used car dealer.
I've searched a bit on the interwebs, and while definitions abound, I can find no reference to the origin of the phrase. Why "last legs"? What happened to the first ones? What has interchangeable legs anyhow?
Best Answer
To add to @Robusto's answer - regarding the origin - the following seems more definitive and is taken from "The Facts on File dictionary of clichés"
However this link dates "The Old Law" as
The exact text as it appears online