"I Just Had Sex" was written by The Lonely Island during the winter of 2010. The comedy troupe, in the same fashion as the recording process for their debut, Incredibad, rented a house in Los Angeles and created a makeshift studio where they would record songs from that album.[4]
The music video for "I Just Had Sex" features Akon, Andy Samberg, and Jorma Taccone singing about how they just had sex with their unsatisfied girlfriends played by Blake Lively and Jessica Alba. The music video takes place in New York City atop the MetLife Building with the backdrops of the Empire State Building, Chrysler Building and the cityscape. Various other locations such as a Central Park, a household, a bakery, a bathroom, a museum, a pub, and a girls' changing room are shown. The song features John McEnroe, first appearing at the line "Having sex can make a nice man of the meanest." The Lonely Island member Akiva Schaffer, who directed the video, also makes several appearances. The album's title is referenced when Jorma sings "she let me wear my chain and turtleneck sweater" while showing him wearing the same outfit that appears on the album cover. The music video ends with the trio launching fireworks from their crotches, parodying Katy Perry's "Firework" music video.
The song was released on December 19, 2010 and sold over 250,000 digital copies in the US in its first two weeks.[citation needed] The song's video was posted to YouTube by The Lonely Island on the same day, and has since gained over 305 million views as of October 2019.[5]