"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.
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 briefly features John McEnroe for the line "Having sex can make a nice man out of the meanest". Fellow 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 USA in its first two weeks. The song's video was posted to YouTube by The Lonely Island on the same day, and has since gained over 200 million views.