In a stunning development that caught Hollywood off guard, David Glasser has agreed to a new deal as chief operating officer and president at the Weinstein Co. — six weeks after his July 30 announcement that he was leaving.

TWC made the announcement Wednesday on the eve of the Toronto Film Festival, saying that after lengthy negotiations throughout the Labor Day weekend, Bob and Harvey Weinstein solidified a new deal.

“I am thrilled to continue to make TWC my home,” said Glasser in a statement. “Bob and Harvey as well as the employees of the Weinstein Co. have been a big part of mine and my wife, Michele’s, lives. After a long weekend in conversations with everyone, we were able to partner on a plan that will keep me at the studio and continue to grow our business for years to come. I believe the coming years will be the most ambitious in TWC history.”

Glasser had announced on July 30 that he was leaving the company in search of a new opportunity, but would stay on to find a replacement as TWC prepared for awards season.

“It has been an incredible run at the Weinstein Company, but I have decided to take some time and explore my options in the industry,” Glasser said in the July 30 statement. “I will remain with TWC until November, where I will work closely with our team to set up the incredible slate for 2015-2016.”

Speculation had boiled since then about a successor and the fate of TWC. Relativity Media president Tucker Tooley was in discussions — reported on Aug. 24 — to come on board but those talks never led to a firm offer.

Adding to the uncertainty surrounding TWC were the August departures of Tom Quinn and Jason Janego, who had headed up TWC’s Radius specialty releasing arm, and Julie Rapaport, Glasser’s former assistant who had become a TWC senior VP and left for Amazon Studios.

TWC has a serious awards contender in “Carol,” starring Cate Blanchett and Rooney Mara, which opens in the U.S. on Nov. 20. And it may have another with Quentin Tarantino’s Western “The Hateful Eight” opening on Christmas Day amid high expectations, given the robust performance of 2012’s “Django Unchained,” which grossed $425 million worldwide.

TWC has been hit-free this year with “Paddington” notching the top gross at $76 million domestically. Jake Gyllenhaal’s boxing drama grossed a respectable $51 million in the U.S. while Helen Mirren’s “Woman in Gold” took in a moderate $33 million. Owen Wilson’s thriller “No Escape” has grossed a modest $20 million in its first two weeks.

The Weinsteins issued statements Wednesday that were effusive in their praise for Glasser, who has been at the company for seven years.

“I have always maintained David Glasser is one of the best COOs and partners my brother and I have ever had,” said TWC co-chairman Bob Weinstein. “David’s return is a huge boost for the company and he is an invaluable member of this team. Although many have tried to claim the title third brother, David is the only one that we would proudly bestow that moniker.”

“I couldn’t imagine continuing this journey without David. He knows the company has huge assets that if managed properly will generate long and powerful financial success,” said co-chairman Harvey Weinstein. “This is starting to feel like Miramax 2.0 so I figure we should join the original Miramax and create the world’s most famous active movie company. With David back that could be a reality.”

TWC also said a number of key executives will be announcing their contract extensions in the coming days. It also said Glasser’s new deal is effective immediately.

Glasser was a key part of TWC when it restructured its debt in 2010 in a deal that took $450 million off the books in exchange for giving Goldman Sachs and Assured Guaranty control of 200 films in the library. That deal came after TWC and investor Ron Burkle were unable to complete a deal with Disney to acquire the Miramax library of 600-plus titles in a complex $625 million deal.

Glasser has also been attempting to sell off TWC’s TV business this year. The division’ shows include “Project Runway” and the MTV drama “Scream.”