Maybe you've seen Whose Line Is It Anyway on TV and wondered what those people are doing.  Maybe you've watched movies like Anchorman and marveled at the off-the-cuff delivery of jokes.  What you're watching is improv comedy in action.
Improv, also known as improvisational theater, is a genre of unplanned performance.  Players collaborate to create the story, dialogue, and characters, usually based on a suggestion from the audience.  Physical objects such as props, settings, and costumes are usually implied by the players as part of the scene.  The actors play games, which are really sets of rules to help anchor the scene and keep everyone on the same page.  
The basic psychological dynamic of improv is that of six year olds at play.  One child makes something up ("Watch out! The floor is made of lava!") and all the others accept it ("Everyone get on the blanket").  Players must react to the offerings of their fellow actors as if they are real and true.  Audiences participate by suspending their disbelief and following along with the scene.  Everyone gets to think like a child again for a while.
There are hundreds of improv games to play.  The most basic example of a game is "Clap Freeze". The MC will ask the audience for a prompt, such as a location, to start the scene.  Two players start a scene using the suggestion.  A third improviser waits off stage, watching the action.  The third will "clap in", freezing the action.  The new actor replaces one of the other actors and starts an entirely new scene, with a new location and entirely new characters.  The game continues, with actors stepping in and out of scenes, until one brings the game back to the original scene.  Games can be either short form or long form.  Short form games are the most common and most popular with audiences.  These are usually two to five minutes in length and may contain many disposable characters and jokes.  Long form improv consists of recurring characters and jokes or themes, and can last longer than 20 minutes.  
There no real over-arching rules to improv comedy[1], but good improv does tend to run on certain principles.  The most famous principle is "yes, and".  This means that anything that an improviser says on stage must be taken as gospel truth.  If one say the sky is purple, other actors must accept this statement, and for the remainder of the game, the sky is purple.  Other principles are things like being chivalrous during the game by accepting responsibility for moving the scene forward.
Improv comedy is a blast.  Playing in fun, watching can be hit and miss.  Some people are amazingly talented and can consistently deliver audiences with a great experience.  Most of us are not so lucky.  While improv can be hit-and-miss, it has moments of sublime absurdity.  Check out your city or town for local troupes for shows or schools that offer classes.