Colter Stevens (Jake Gyllenhaal) is a decorated army helicopter pilot who finds himself on a mission to locate the maker of a bomb which exploded and destroyed a train headed into Chicago. Stevens is isolated inside a chamber, where Air Force Capt. Colleen Goodwin (Vera Farmiga) explains to Stevens through a computer screen that he is inside the Source Code, a program that allows him to take over someone's body in his or her last eight minutes of life.
Stevens' mission is to locate the bomb, discover who built it, and report back to Goodwin before the bomber can detonate a second larger bomb, a dirty nuclear device, in downtown Chicago, which could cause the deaths of millions of people. Stevens can perform different actions each time and learn from those actions. Goodwin and the Source Code's creator, Dr. Rutledge (Jeffrey Wright), tell him that the Source Code is not a simulation, but a visit into the past in the form of an alternative reality. He's told that he cannot truly alter the past to save any of the passengers, but that he must gather intel that can be used to alter the future and prevent a future attack.
Every time he is sent into the train he awakens as Sean Fentress, a teacher, sitting across from a woman named Christina Warren (Michelle Monaghan). A series of events repeat each time with slight variations while he goes on searching for the terrorist and deepening his understanding of Christina, until the bomb that destroys the train goes off and Stevens (as Fentress) dies, sending him back to the chamber.
Stevens has no memory of how he arrived to the mission; his last memory is of flying in a recent mission in Afghanistan while taking on enemy gunfire. Confused and frustrated, Stevens wonders how he got assigned to this project. Using a cellphone, he eventually discovers that he supposedly died in the war two months ago and that his severely injured body was apparently appropriated by the Air Force and used by Rutledge to enter the Source Code.
Stevens is sent back several more times. The second time he locates the bomb in the ventilation shaft above the bathroom. Each time he learns more, both about the terrorist attack and his real life personal situation, even though Rutledge and Goodwin constantly direct him to focus on finding the bomber. Stevens resolves to complete his mission, now with the added personal goal of saving Christina and the people on the train if at all possible.
He eventually discovers that the bomber is an American extremist named Derek Frost (Michael Arden). Stevens pursues Frost to a white van where the radioactive bomb is hidden. Stevens is eventually shot dead in the confrontation, but still able to gather enough information about Frost to inform Rutledge and Goodwin after he awakes from the source code. Authorities are able to apprehend Frost and save Chicago before the second bomb is detonated.
With the mission accomplished, Rutledge orders Stevens' memory to be erased and stored for reuse in further missions. But Stevens persuades Goodwin to send him in one more time and give him one last chance to avert the train disaster. Goodwin agrees that he deserves to be allowed to die in peace afterwards instead of being held alive as a military artifact.