Samuel also said to Saul, “The LORD sent me to anoint you king over His people, over Israel. Now therefore, heed the voice of the words of the LORD. Thus says the LORD of hosts: ‘I will punish Amalek for what he did to Israel, how he ambushed him on the way when he came up from Egypt. Now go and attack Amalek, and utterly destroy all that they have, and do not spare them. But kill both man and woman, infant and nursing child, ox and sheep, camel and donkey.’”
So Saul gathered the people together and numbered them in Telaim, two hundred thousand foot soldiers and ten thousand men of Judah. And Saul came to a city of Amalek, and lay in wait in the valley. (1 Samuel 15:1-5)
God’s mercy for Israel meant judgment for the Amalekites. When Israel was on its way out of Egypt, the Amalekites attacked them at a place called Rephidim. Joshua led a fight against them. Moses stood with his staff raised. While he held it up, Israel was winning. If he lowered his hands, the Amalekites started to win. So Aaron and Hur held his hands up until Joshua and his men were finally victorious. God told Moses that he would one day blot out the name of the Amalekites (see Exodus 17:14 and Deuteronomy 25:17-19).
Therefore, when Samuel told Saul to wipe out every last Amalekite, he was telling Saul to fulfill a promise that God had made Moses.
Saul, however, did not completely carry out the will of God. He spared the Amalekite king, Agag, along with the best sheep and cattle. This violation of God’s command would cost Saul his throne. Samuel told Saul that obedience was better than sacrifice and that rebellion and arrogance were like divination and idolatry. Saul was, for all practical purposes, rejecting God—just as that unnamed man in the time of Moses had rejected God by insisting on gathering wood on the Sabbath.