I remember reading that Princip had left the botched attack and went to a cafe to lay low. Then apparently the car of the Archduke after fleeing the scene of the attack wound up stopping in front of the cafe where Pricip had been sitting. Princip still in possession of his gun saw the opportunity and took it.
I could be wrong ofcourse, it's been a while since I read that.
Lets see.. I wish I had some of my books with me. I'll be back with a couple when I can think of them.