“If we try to play our own version of identity politics and try to fuel ourselves based on darker emotions, that’s not productive,” he said. He made calls to several of the Republican presidential candidates to outline the agenda; Mr. Trump feigned mild interest but they did not speak again. (The Trump campaign did not return emails with questions for this article. Mr. Ryan also declined to be interviewed.) Mr. Ryan had hoped that Mr. Trump would eventually embrace his plan.

When Mr. Trump clinched the nomination in May, Mr. Ryan was rattled, said several people who talked to him that day.

“The conventional wisdom among the people we talked to here was, ‘Don’t worry, this will end,’” said Charlie Sykes, a former conservative talk radio host in Milwaukee and a friend of Mr. Ryan’s. “So it was a huge shock. I think a lot of us here believed we were going be the firewall in Wisconsin, that there would be an outbreak of rationality.”

With campaign rhetoric getting increasingly contentious, Mr. Ryan made the unusual choice of announcing that he was not ready to endorse Mr. Trump. None of this pleased Mr. Priebus, who prided himself on building the modern Republican Party in Wisconsin and longed for unity going into the race against Mrs. Clinton.

In text messages and phone calls, Mr. Priebus tried to persuade Mr. Ryan — who was relishing his independence — to accept Mr. Trump, said numerous officials with knowledge of the exchanges who requested anonymity to discuss internal party matters. Mr. Trump would yell at Mr. Priebus and in turn Mr. Priebus would needle Mr. Ryan.

When that did not work, Mr. Trump claimed Mr. Ryan had agreed to endorse him before a visit to Capitol Hill to try to woo fellow Republicans, a claim Mr. Ryan viewed as a serious breach. “That was the first realization that Trump wasn’t just a public persona,” said a Republican involved in planning the meeting, who insisted on anonymity so as not to alienate Mr. Trump, “but that his staff does not deal in good faith.”

In June, after a period of relative silence on Mr. Trump’s part, Mr. Ryan finally felt comfortable enough to endorse him. Staff members of both men began to coordinate for the Republican National Convention. But days later Mr. Ryan aggressively criticized Mr. Trump for his remarks about a Hispanic judge.