I just learned this in two different classes.
In the case of the two people in the desert, the one who drinks the water will live and the one who doesn't will die, but the one who drinks the water is not actively killing the other -- he's just drinking his water. The other person isn't being murdered; he's dying of thirst. R' Akiva's teaching is akin to the instruction anyone who's flown has heard: secure your own oxygen mask first before helping others. You are required to protect your own life first, according to R' Akiva. (Note: there are also cases where we're required to intervene, e.g. to save someone from a pursuer, which were addressed in the aforementioned classes but seem beyond the scope of this question.)
In the case of the person who was ordered to kill another or be killed himself, however, saving himself would require positive action to kill the other. That's murder and he must instead give up his own life. It's not so much that the other's life takes precedence; neither life takes precedence over the other, but not violating the commandment against murder takes precedence over saving one's life.
What about a case where the other person will be killed (not die of other causes) but you don't do it yourself? Can you take positive action that leads to someone's death at another's hand? Yerushalmi Terumot 8:4 talks about this case. If bandits set upon a group and say to them: "give up one of your number for us to kill and we'll spare the rest of you", they do not comply -- even though they are not actively doing the killing, they are still deciding whom to kill. That's on the wrong side of the line. If the bandits specified a particular person, however, the group can turn him over. Reish Lakish says they can only turn him over if he's already liable for death (like Sheva ben Bichri in II Samuel 20), meaning that it's still not murder, but R' Yochanan says even if he's not already liable to death they can turn him over to the bandits to be murdered. (I do not know which way halacha rules in the end; if this is a practical matter for you, please consult your rabbi.)