Parag was exhausted at a virtual meeting last week.

Mr. Agrawal had spent the past six weeks steering the company through a $44 billion sale to Musk, the world's richest person. Some employees revolted against their new owner because he had criticized the social media service. Others were upset by the recent corporate shake-ups. Mr. Musk was likely to force Mr. Agrawal out of his job.

Two people with knowledge of the meeting said that Mr. Agrawal was talking about the issues of the company and the attention it received. He said he would move forward with his plans for the company and that he had a sense of acceptance of his situation.

The company's core product, its depth of technology, the business, free speech, and what leadership looks like are some of the areas that Mr. Agrawal said were key to improve upon. The people said that some executives left the meeting with renewed energy.

It was what Mr. Agrawal could do. Because of all the top jobs in tech, the 38 year old is in one of them.

Since November, the Indian-born executive has been in charge of the company. After years of missed growth and financial goals, he was expected to turn the social media site around. Within months, Mr. Musk swooped in and turned Mr. Agrawal into a "lame duck" who must manage a restive work force and deal with the mounting economic challenges before he gets kicked out of the company.

There is no one in the world who would want to be in those shoes.

Mr. Agrawal faces a soft landing as he grapples with the situation. Mr. Agrawal would make tens of millions if Mr. Musk removed him as CEO. He was granted a compensation package of $1 million, plus bonuses, as well as restricted stock units and performance-based stock units valued at $12.5 million.

The annual shareholder meeting will be held virtually, and Mr. Agrawal will appear at it. The deal with Mr. Musk is not expected to be discussed by executives. The meeting will be procedural and short according to a regulatory filing.

ImageBy March, Elon Musk had begun building a large stake in Twitter.
By March, Elon Musk had begun building a large stake in Twitter.Credit...Pool photo by Patrick Pleul
By March, Elon Musk had begun building a large stake in Twitter.

Employees and advisers said that Mr. Agrawal was working with bankers and board members to close the sale of the company to Mr. Musk.

Mr. Agrawal has doubled down on his plans to change the social networking site. After the company missed financial goals, he fired two top executives, paused most hiring and pulled back on discretionary spending. He wants to make the platform more attractive to new users, and move more swiftly to debut new products, according to a presentation at a company meeting this month.

According to a recording of the meeting obtained by The New York Times, Mr. Agrawal said that they had been through a period of uncertainty.

Mr. Agrawal was an engineer at the time of his PhD studies. He rose through the ranks and became the company's chief technology officer. He has more than 610,000 followers on the service and has spent most of his career at the company.

Mr. Agrawal built relationships with his engineering peers and Mr. Dorsey while he was chief technology officer. He shared Mr. Dorsey's vision for the future of the platform, which was to rely more on machine learning and decentralize its services to give users more control.

The engineer went from overseeing a handful of employees to instantly managing more than 7,000 people when Mr. Agrawal took over.

Mr. Agrawal made some changes. He dismissed two executives responsible for design and engineering. Remaining leaders were given more responsibilities. The new structure would clarify who was responsible for what tasks and speed up decision-making, he said in internal emails seen by The Times.

Mr. Agrawal pushed out two security executives. He said in an internal memo that the organization was not being led according to his expectations.

ImageParag Agrawal, who became Twitter’s chief executive in November. He has spent most of his career at the social media company.
Parag Agrawal, who became Twitter’s chief executive in November. He has spent most of his career at the social media company.Credit...Twitter, via Getty Images
Parag Agrawal, who became Twitter’s chief executive in November. He has spent most of his career at the social media company.

Some of the ousted executives were praised by some of the employees. Others were surprised that Mr. Agrawal had dismissed longstanding leaders.

By March, Mr. Musk was building up a large stake in the company. Mr. Musk talked to Mr. Agrawal on March 31 to convince him to join the board. Mr. Musk reversed course after initially agreeing. According to the filing, Mr. Musk had an idea of starting a new social media company.

It was Mr. Agrawal's first encounter with Mr. Musk. Mr. Musk launched a takeover bid for the company, sealed the deal, and then needled Mr. Agrawal over issues such as fake accounts. Mr. Musk replied to Mr. Agrawal with a poop symbol.

According to 10 current and former employees who spoke on the condition of anonymity, Mr. Agrawal was disliked by some employees. He told workers that he couldn't give them any information about the deal with Mr. Musk. He was absent from an internal employee chat and initially quiet at company meetings.

According to two people with knowledge of the matter, Mr. Agrawal's supporters said he was legally restricted from sharing information about the deal, and he expressed his frustration with being unable to say more about it. After the agreement was signed, the company held staff meetings and sent out more than a dozen emails. Last week, employees were allowed to ask Ned Segal, the chief financial officer, and the head of legal and policy questions about the deal.

Mr. Agrawal is more charming in smaller groups. The company that had been resistant to change was one of the reasons for his changes being long overdue.

Other employees have expressed their excitement for Mr. Musk's ownership of the company.

Mr. Agrawal has detractors. At company meetings in recent weeks, he sometimes said that nothing would change, and some employees have mocked his comments.

Several people said that many employees are uncertain about their futures. The people said that some people were not happy about the golden parachutes that Mr. Agrawal and other top executives would receive if they were fired.

ImageTwitter’s headquarters in San Francisco.
Twitter’s headquarters in San Francisco.Credit...Jim Wilson/The New York Times
Twitter’s headquarters in San Francisco.

Mr. Agrawal has told people that he will carry on with his plans even if Mr. Musk takes over. He tried to rally workers after cutting spending and freezing hiring.

During this time of change, it's critical that we continue to strengthen our work through increased accountability and execution, and that's what he wrote in an email to employees, which was seen by The Times.

Ryan Mac was involved in reporting.