After witnessing an act of bravery in the marketplace of the royal city, the street urchin Dastan is adopted by King Sharaman, becoming a prince of Persia. Years later, the grown Dastan (Jake Gyllenhaal) spearheads an attack on Alamut, which the king's brother Nizam (Ben Kingsley) has accused of selling weapons to Persia's enemies. During the battle, the city's princess Tamina (Gemma Arterton) is captured and Dastan acquires a strange dagger. During a banquet, Dastan gives Sharaman a cloak as a gift and after he declares Tamina Dastan's future wife the cloak apparently burns him to the touch and kills him. Dastan is framed for murder but narrowly escapes from Alamut with Tamina, evading the king's high-born sons Garsiv (Toby Kebbell) and Tus (Richard Coyle). After being attacked by Tamina, Dastan finds that the sands within the dagger's hilt allow him to rewind time by a minute and retain knowledge of what happened before. While going to Avrat for Sharaman's funeral, the two encounter a shady merchant called Sheik Amar (Alfred Molina), and Dastan encounters Nizam, who pretends to be sympathetic to Dastan's plight. At their meeting, Dastan sees Nizam's hands burned and realizes in horror that his uncle had murdered Sharaman. Dastan escapes from an ambush with the princess, but Nizam secretly sets a group of Hassansins, corrupted Persian warriors, on their tail, while Tus had sent the angry Garsiv and some men to find Dastan.
As they are on the run, Tamina tells Dastan about the dagger's origins: the gods had decided to sweep mankind from the earth with a great sandstorm because of their sin. But a young girl pleaded with the gods and convinced them to withhold their wrath. The sands from the storms were stored in a great hollow crystal called the Sandglass, with the dagger, called the Dagger of Time, being the only thing that could break the crystal. The Sandglass was hidden beneath Alamut with Tamina's family, descended from the young girl who saved mankind, as its guardians. It is shown that Nizam orchestrated the siege of Alamut so he could hunt for the Sandglass and use the sands to change an event in his youth where he saved Sharaman from a lion, thereby ensuring Nizam would become king.
Seeing that the sands’ release would destroy the world, Tamina is willing to return the dagger to the place where it was given, giving her life in the process. They reach the dagger's resting place in the Hindu Kush, after being captured by Sheik Amar, but are ambushed by soldiers under the command of Garsiv. Dastan manages to convince Garsiv of his innocence, but the Hassansins attack, take the dagger from Tamina and kill Garsiv. Together with Sheik Amar, his Umbakan guardian Seso and his retinue, Dastan and Tamina head back to Alamut. After retaking the dagger from a Hassansin, who had promptly ended Seso's life, Dastan uses it on himself in front of Tus, showing him the power of the dagger and his own innocence. But Nizam arrives, kills Tus and takes the dagger, leaving Dastan to die. Tamina saves him and they go down into the catacombs of Alamut.
After confronting and defeating Zolm, the Hassansin leader, Dastan and Tamina arrive in the chamber of the Sandglass as Nizam stabs it, starting the release of the sands. When they reach him, Nizam attacks them, and Tamina, who has grown to love the prince, sacrifices herself to give Dastan his chance. Dastan manages to remove the dagger from the Sandglass, preventing the apocalypse, then time is rewound to just after the siege of Alamut, undoing all the events he has lived through. Dastan manages to find his brothers and expose Nizam of his treachery, who attacks Dastan in a rage and is soon killed by Tus.
As an apology for the ransacking of her city, Tus suggests that Dastan and Tamina are married as a goodwill pact. As they converse afterwords, Dastan hints at his knowledge of the dagger’s power and says he looks forward to their future together.