It’s in the OED:
bq. Expressing frustration at the realization that things have turned out badly or not as planned, or that one has just said or done something foolish. Also (usu. mildly derogatory): implying that another person has said or done something foolish.
The best part is when it was first used: not by Homer Simpson, but in a 1945 BBC radio show.
Hat tip to Eric Lawrence.