Image copyright Getty Images Image caption James Gunn has worked on the Guardians of the Galaxy films and the Avengers franchise

Disney has removed James Gunn as director of Guardians of the Galaxy Vol. 3 after a number of offensive social media posts resurfaced online.

The American filmmaker apologised after old tweets in which he appeared to joke about paedophilia and rape were unearthed and widely shared.

But Walt Disney Studios Chairman Alan Horn announced his sacking on Friday.

"The offensive attitudes and statements discovered on James' Twitter feed are indefensible," he said in a statement.

"[They are] inconsistent with our studio's values, and we have severed our business relationship with him."

Gunn wrote and directed both of the first two Guardians of the Galaxy films, which starred the likes of Chris Pratt, Zoe Saldana and Bradley Cooper.

The first instalment was one of Marvel's most successful films, making more than $771m (£540m) at the worldwide box office.

Gunn has also worked on the hugely-successful Avengers franchise.

There has been no immediate response from the filmmaker, but in a series of tweets posted on Thursday he addressed the controversy surrounding his old posts.

"I viewed myself as a provocateur, making movies and telling jokes that were outrageous and taboo," he said. "I am very, very different than I was a few years ago."

"I have apologized for humor of mine that hurt people. I truly felt sorry and meant every word of my apologies," he added.

The now-deleted posts first came to light when conservative news website the Daily Caller unearthed them.

A number of conservative pundits then shared the tweets and called for Mr Gunn to be dropped by Disney.

The director has been an outspoken critic of President Donald Trump. Earlier this month, he accused the US leader of "treason" over comments he made at a summit with his Russian counterpart Vladimir Putin.

It is not clear who will replace him on Guardians of the Galaxy Vol. 3, which was reportedly set to be filmed next year.