NBC has tracked down and fired the staffer who leaked the infamous — and wildly entertaining — tape of Lawrence O’Donnell’s meltdown during which he swore at his crew because of “insanity in my earpiece.”

Multiple sources said that a male “Today” show editor was found to be the culprit who compiled and leaked the eight-minute video of O’Donnell raging at staff during breaks in an Aug. 29 live broadcast of his show “The Last Word.”

In the clip, a furious O’Donnell slams his fist on his desk and rants about “insanity in the control room” and “stop the hammering!” and what he calls “f—king out-of-control s—t.”

One source said, “The video of Lawrence O’Donnell was leaked on Sept. 20. The leaker was identified, confronted and fired on Sept. 26. It turned out to be a ‘Today’ show editor who said he did it because he thought it was funny. But it wasn’t exactly the perfect crime — he left a very clear trail.”

Sources connected with the leak had told Page Six the video was slipped to Mediaite as a broadcast-quality digital clip — and that only a handful of people are believed to be capable of accessing and transmitting such a file.

We’re now told that the leaker, whose name has not been released, had left a clear digital trail that allowed NBC honchos to track him down. NBC declined to comment.

O’Donnell did not comment about the leaker being caught, but after the tape leaked, he tweeted, “A better anchorman and a better person would’ve had a better reaction to technical difficulties.”

There had been a theory that the leak was to put O’Donnell in his place after he angered NBC honcho Andy Lack — who also oversees MSNBC — in May by tweeting about his tense contract negotiations.

O’Donnell told us at the time: “This is a ridiculous conspiracy theory. There’s only one person to blame for this video: me. Andy Lack brought me to MSNBC when he created the network in 1996. We were friends before that and have always remained friends.”