The Joker (appropriately enough) tried to pull this once on Batman (1966). After winning parole and faking his own kidnapping by Catwoman, he protests that he and Catwoman are just playing pranks when Batman and Robin catch up with them as they're plotting a heist.
On Criminal Minds a psychopathic teenager who had already committed several murders held a knife to his sister's throat, about to kill her in front of their horrified mother because of his jealousy over her perceived favoritism. When the FBI agents arrived in the nick of time and ordered him to drop the knife, he tried to sound casual with, "Fine. I was only kidding anyway." It didn't fool anyone.
Larry David in Curb Your Enthusiasm makes frequent use of this (usually as a last resort if he needs something from whoever he offended).
A rare example without overtones of racism or outright cruelty: in The Dick Van Dyke Show episode "Punch Thy Neighbor", Jerry Helper (the next door neighbor) keeps going around saying The Alan Brady Show — on which Robert Petrie (Dick Van Dyke) works — wasn't funny. Rob was quite upset. Jerry keeps saying that his insults don't matter because it's all in fun, despite the effect the negative word-of-mouth could have on Rob's livelihood. Rob justly points out that nobody can tell when Jerry is joking and one of these days, he'll meet someone who doesn't care.
In Downton Abbey, when Larry Grey is called out for using a spiked drink to embarrass Tom at a dinner party, he responds with this excuse. Mary immediately rejects this as "A bully's defence!"
Mr. Brown, the first hotel guest on Fawlty Towers, does this after joking about needing a double bed and suggestively saying "hello" to Polly. His boorishness is justified when we learn that Mr. Brown is an undercover police officer, posing as a guest to investigate the phony Lord Melbury.
In "Second Sons", Tyrion Lannister makes a Freudian Threat to King Joffrey after one too many Kick the Dog moments. After a Stunned Silence, his father Lord Tywin points out that Tyrion is drunk. Tyrion regains control of himself and tries to pass his threat off as a bad joke, engaging in some Self-Deprecation and staggering off drunkenly. (He only has to exaggerate his inebriation a tiny bit because he is in fact quite drunk already.) It's unclear if anyone is fooled by this (Joffrey certainly isn't) but was a necessary face-saving gesture anyway.
Comes up again in "Mhysa", when Joffrey says he wants to have Robb Stark's severed head served to Robb's sister Sansa at Joffrey's wedding feast. Everyone else in the room is appalled, but his mother Cersei tries to brush it off as just a joke. Joffrey, however, insists that he was being serious.
When Littlefinger makes a snide comment about Queen Cersei's twincest, she puts him in his place by ordering her bodyguards to cut his throat on the spot, then cancelling the order at the last second with this trope.
In the Hannah Montana episode "Judge Me Tender", a Simon Cowell parody character issues one of these, then immediately retracts it, after saying both Hannah and the judge for whom she was filling in were boring.
On the first season of The Joe Schmo Show, Hutch "the asshole" used this as his go-to excuse for his regular harassment and bullying of Kip "the gay guy," particularly his threats to toss him in the pool over his fear of water and stealing his photo album and filling it with pictures of his buttocks.
A new neighbor boy spreading malicious lies about Malcolm, turning the entire neighborhood against him. When Malcolm confronts him, the kid says, "Hey, it's just a joke. Lighten up," and continues doing it.
There's also an episode of Cynthia's early appearance, where she kept saying things that hinted at her having done horrible things or of horrible things having been done to her. She always adds "Just kidding!" after gaining a horrified look from the others. Malcolm eventually calls her out on many things about her, including how her 'jokes' are not funny and adding 'just kidding' does not alter the fact or make them okay. Cynthia changed her ways.
The Office (US): Michael Scott often finds himself caught in these after an egregious faux-pas or a joke in really bad taste.
At the end of the Psycho Rangers story arc of Power Rangers in Space, an exhausted Andros shuffles off to his bunk with the intention of getting some much needed sleep. When he rounds the corner, he finds Psycho Red, inexplicably still alive. He attacks the Psycho, only to learn that it's actually Zane in disguise.
Andros: Oh, it's just a joke. Zane: Yeah! Andros: Good one! (judo flips Zane over his shoulder)
Punk'd: This was the whole premise of the show. During the series, Ashton Kutcher did some “pranks” against celebrities that were actually downright terrible and justify it with “I’m just kidding around.” It’s worth noting that in the years since the series, many celebrities have said they did NOT appreciate his humor, and Ashton himself has stated that even as early as during the series run, he would be shunned from parties because of it and some celebrities would actually try and fight him.
Rome. Julius Caesar sends Vorenus to bribe a former army colleague. Honest to a fault but loyal to his superior, Vorenus does so and reports back. Caesar comments that he didn't think the man would sell out so cheaply. "I must send you to handle all of my corruptions." Manipulative Bastard that he is, Caesar quickly sees how uncomfortable this makes Vorenus and says that he was only joking.
Scrubs: the Janitor brings a cage to a baby shower(for the baby). When he gets weird looks he then plays it off like he was just joking and really brought it just in case the child gets a puppy later on. We later see him on the phone "No, Ma, 'baby cage, playpen' is not like 'tom-ay-to, tom-ah-to'!"
Usually, when a character says something that pisses off another character, they justify it as them just "breaking balls", but even then it's not enough to save them from being assaulted by the target of their barbs.
Probably the most extreme example on the show is when Vito Spatafore is spotted by two New York associates at a gay nightclub while he's flirting with another man and dressed in a motorbiker outfit, which he tries to pass off as a joke in order to prevent them from outing him. It doesn't work.
In Toshiie to Matsu, Oda Nobunaga attempts to pass off a particularly tasteless move (displaying the gold-plated skull of his sister's dead husband, and ordering her and her new fiancee to drink from the skullcap) on his part as a joke.
The Twilight Zone (1959): In "The Encounter", Fenton regularly makes bigoted remarks about Arthur Takamori's Japanese-American heritage and then claims that he was just joking when Arthur takes offense.
The Windsors: Prince Andrew continually torments those around him in various serious ways but writes it all off as just being a joke.
The Young Pope: Lenny, the eponymous young pope, does this repeatedly. He frequently makes rude or upsetting statements and then claims to be just joking. It's never quite clear when he's being intentionally manipulative and when he's just socially awkward. He's never actually joking.