The festival is to take place Nov. 7-11.
Three-time Golden Globe Awards show host Gervais will kick off the festival with an in-depth conversation at Town Hall Nov. 7.
Hart will become only one of a handful of comedians -- such as Bob Hope, George Burns, Eddie Izzard, Chris Rock, Andrew "Dice" Clay and Dane Cook -- to headline the Madison Square Garden arena. He will bring his "Let Me Explain Tour" to MSG Nov. 10.
HBO's "Real Time" host Bill Maher is to again play the Beacon Theatre Nov. 10, while award-winning actor and comedian Robin Williams will return to the festival with a conversation with Emmy Award-winning television director David Steinberg at the 92nd Street Y Nov. 11.
Ansari, star of NBC's hit series Parks and Recreation, will perform at the Apollo Theater Nov. 9 and at Carnegie Hall Nov. 10.
"The New York Comedy Festival continues to solidify New York City's position as the comedy capital of the world," Caroline Hirsch, founder of the festival and owner of Carolines on Broadway, said in a statement Wednesday. "Once again, we're thrilled to partner with Comedy Central and to continue to grow the festival brand with an incredible line-up of talent and programming. We have some of our favorite comedians returning as well as introducing some who have not been part of the festival in the past. There won't be any shortage of laughs this November."