LOS ANGELES — Disney is taking back James Gunn, the creative force behind its “Guardians of the Galaxy” movie franchise, reversing its contentious decision in July to fire the filmmaker for offensive jokes he wrote on Twitter several years ago.

The tweets by Mr. Gunn, who wrote and directed the Marvel superhero film “Guardians of the Galaxy” in 2014 and delivered a smash sequel in 2017, contained jokes about pedophilia, AIDS, rape and the Sept. 11, 2001, attacks. Two far-right provocateurs, Mike Cernovich and Jack Posobiec, threw a spotlight on the comments — written between 2009 and 2012 — after Mr. Gunn harshly criticized President Trump online.

Disney executives seemed to acknowledge on Friday that they made a misstep of their own in almost immediately firing Mr. Gunn in the aftermath: At the time, “Guardians” cast members condemned the decision as an overreaction to the “mob mentality” of the internet. If nothing else, the reversal reflects the challenges that Hollywood studios face as they contend with online furors over past behavior in response to the #MeToo and Time’s Up movements, all while trying to protect billion-dollar film properties.

Walt Disney Studios revealed Mr. Gunn’s reinstatement as the director of “Guardians of the Galaxy 3” in an article on Deadline.com, a trade news site. Disney declined to comment further, except to confirm the report’s accuracy. In a statement on Twitter, Mr. Gunn called himself “incredibly humbled” and “tremendously grateful” to those who had supported him in recent months.