When Sam and his gang ambushed the Knightmare, really Ashildr, and the Twelfth Doctor, determined to scare them off their patch, they were outwitted by the pair and fled in fear.
When it was time for Sam to face the noose at Tyburn, he greeted it with bravery, wit and humour, using jokes to delay the moment of his death. The Doctor joined in with Sam's gallows humour and managed to earn him a pardon, but this was short lived, as Ashildr used the amulet to end Sam's life and open the portal.
When the full scale of Leandro's plan was revealed, and Leonian ships appeared through the rift, the Doctor realised Sam's death must be reversed to close the portal. Ashildr used the spare immortality chip the Doctor had given her centuries before to resurrect Sam — the portal was closed and Sam was saved.
Afterwards, the Doctor noted that he did not know if Swift would be made immortal like Ashildr or if the energy had been used up stopping the amulet, so he asked Ashildr to promise to watch out for him. (TV: The Woman Who Lived)