Image copyright Getty Images Image caption Harmon said he "quickly realised the content was way too distasteful"

The creator of US sitcom Community has apologised after a "distasteful" video from 2009 in which he pretends to rape a baby doll surfaced online.

Dan Harmon, who also co-created animated series Rick and Morty, said he had wanted "to parody the series Dexter and only succeeded in offending".

He said in a statement: "Nobody should ever have to see what you saw and for that, I sincerely apologise."

Adult Swim, which airs Rick and Morty, said Harmon had shown "poor judgement".

Its statement continued: "Dan recognised his mistake at the time and has apologised.

"He understands there is no place for this type of content here at Adult Swim."

Image copyright Getty Images Image caption The US producer created Rick and Morty with Justin Roiland (left)

In the video, intended as the pilot for a series called Daryl, Harmon is seen breaking into a house and simulating rape on an infant doll.

"I quickly realised the content was way too distasteful and took the video down immediately," he said.

The 43-year-old writer and producer is best known for Community, a sitcom set in a community college, which ran from 2009 to 2015.

Production of the sitcom was marked by a public feud between Harmon and actor Chevy Chase, who left the show in 2012.

Rick and Morty, which first aired in 2013, is an anarchic animated sitcom that follows the adventures of a mad scientist and his grandson.

The show has been a big hit on Adult Swim, Cartoon Network's night-time haven for alternative and adult-oriented animation.

Harmon's apology follows Disney's decision to remove James Gunn as director of Guardians of the Galaxy Vol 3 over some offensive social media posts.

The US film-maker apologised after old tweets in which he appeared to joke about paedophilia and rape were unearthed and widely shared.

Follow us on Facebook, on Twitter @BBCNewsEnts, or on Instagram at bbcnewsents. If you have a story suggestion email entertainment.news@bbc.co.uk.