Actually, yea, as people have said, you could have definitely gotten away. First, if you had stabbed sooner, and kept moving, the pyro might not even have gotten you. Second, since he was obviously following you, I think running back toward spawn is a good move, but, you could have gone for either health pack. Third, you actually almost juked him when you went into the tunnel after faking for the big wide tunnel, if you had just kept running and go for the big health, you would have lived. Fourth, get better teammates who can kill a LITERAL wm1 pyro.
The pyro didn't really have a good chance to m2 you into a wall, and the literal holding down of m1 is comical :3. But Boo is correct, m2 is even worse against spies. Best advice: don't get caught by a pyro.