Conveniently-Timed Guard

The lead character has just successfully carried out their tricky infiltration of some high-security facility and copied the information/stolen the technology/rescued the prisoner/what-have-you. Just as they're done, in wanders some random security guard, who sounds the alarm. Cue the action sequence.

Basically it's a way for a Spy Drama to have its cake and eat it too. You want to see a perfectly-executed piece of espionage, but you also want to see the lead kicking and shooting and fleeing? Throw in some nicely-timed security personnel and you can have it both ways. Although sometimes you have to wonder, did the question "What do we do about the security patrol?" never even come up during planning? In Spy Fiction, the fact that the enemy would quickly realise that their secret files had been stolen also rarely seems to come up.

Otherwise, this trope is something of an example of Truth in Television. It is surprising how many crimes are stopped because police or security forces happened to show up at just the wrong time for the criminals, or someone saw something and called the police.

Examples:

Anime and Manga

 * Mai-HiME, although it's subverted in two ways: first, Mikoto triggers the alarm before Mai and Natsuki even manage to get into the (abandoned) facility, and second, when the guards arrive just as the girls are leaving, Mai persuades the other two to surrender despite their readiness to fight. They later escape anyway, with the help of a conveniently-timed ambush.

Fanfic

 * Masses to Masses: Just before Ian has his eyelids torn off by a furious Ricardo Fernandez, Garrus bursts in and shoots the bastard.

Live Action Television

 * This trope is particularly favoured by Alias, which does it almost Once an Episode.
 * Happens on occasion in Burn Notice, usually to the delight of the 'narrator' who always has good ideas on how to effectively deal with such a predicament.

Web Original

 * Red vs. Blue In the second episode of Season 9, when the guard catches South stealing data from the terminal

Other
"Hay Lin: "Why not just take out a guard and blend in?"
 * Shadowmaster Chronicles parodies and subverts it.

Dakota: "Because that's stupid. The point of espionage is to NOT BE NOTICED BY ANYONE. What if that guard had buddies? Or was invited to play poker or something?""