Israel and Amalek fight a war at the end of Parshat Beshalach. Israel's success in the battle is dictated by the position of Moshe's hands - when they are raised to the sky, Israel prevails, but when he gets tired and lowers them, Amalek begins to win. This of course is very strange and begs for an explanation.
The Mishnah (Rosh Hashana 3:6) states that Moshe's hands simply reflected Israel's attitude towards God. When the Jews looked "up" and trusted in God they prevailed; when they looked "down" and ignored God they lost. This is a nice explanation of the normal workings of reward and punishment, but it's not the simple meaning of the passage. I'll come back to the Mishna, but we must look elsewhere for the pshat.
In the paragraph immediately before the Amalek war, Israel journeyed to Refidim. There was no water available, and the people accused Moshe of bringing them to the desert in order to die. Moshe complained that the people were about to stone him to death, and God instructed Moshe to hit a rock (with the staff he used in Egypt) in order to miraculously obtain water. In the conclusion, it is mentioned that the people "tried God, saying, 'Is God among us or not?' " But reading the whole passage, you see that the people never mention God; they only complain about their thirst and accuse Moshe of scheming to kill them.
One major purpose of the ten plagues and the splitting of the sea was to make God's existence and presence known - to Egypt and to the Jews. It must have been hard to deny that God took a part in those miraculous events. But now that the Jews were alone in the desert, without water, and without any miracles taking place - the thought arose, perhaps God had left them, and their current situation was only a personal initiative of Moshe? If so, then Moshe should be removed from power, and the people should either look directly for God or else find a practical way of obtaining water and other needs. Reading this mood, Moshe feared that the people were about to stone him.
At this point, the people needed to be made to recognize that Moshe's leadership was in fact God's leadership - that even if at some particular moment no miracles were being performed, God nevertheless was in charge and had retained Moshe as His earthly representative. The first opportunity to demonstrate this was the production of water in Horev. Moshe was told to hit the rock specifically with the staff he used in Egypt, to demonstrate that nothing had changed since Egypt - God was still performing miracles for Moshe.
But the miracle of the water was performed only in front of seventy elders. While the people's complaint was temporarily silenced by the quenching of their thirst, they had not really absorbed the lesson that God was still with Moshe. The battle with Amalek followed immediately after the water was produced. In order demonstrate the Moshe/God connection to the entire people, the success of the battle was to miraculously depend entirely the positioning of Moshe's hands.
There are several obscure details about the battle which make perfect sense when it is seen as a public demonstration of Moshe's connection to God. Why did Moshe have to be on top of a hill? (To make the lesson public.) Why did he need to hold the "staff of God" - apparently the same staff used in Egypt and at Horev? (To demonstrate that God was performing miracles for Moshe just as in Egypt.) Why did Moshe's hands need to get really heavy before his aides arrived to hold them up? (If there wasn't a period in which Moshe's hands had fallen and the people had suffered in battle, they might have thought his hands had nothing to do with their success.)
In this vein, the Mishna can still be understood, though slightly differently from its simple reading. In Refidim the people demonstrated a serious lack of faith in God's protection. As punishment they had to fight a war with Amalek. But during the battle, due to the visible connection between Moshe's behavior and their success, they regained faith that God was still with Moshe and with them. With this regained faith, the Israelites were now worthy of the next event the Torah records involving them: the giving of the Torah at Sinai.
[Update: The article "Mei Meriva" by Shmuel Cohen (Alon Shvut Bogrim 3, 1994) similarly argues that the people tend to believe that Moshe rather than God is responsible for their situation, even in the 40th year.]