It started to sink in for Muhammad Wilkerson and his camp last weekend, that a long-term contract with the Jets was not going to happen.

Five days later, Wilkerson signed a five-year, $86 million deal with the Jets, shocking the NFL. How did it get from no chance to a deadline deal? With some late-night emails and plenty of phone calls right down to the wire.

Before this month, the Jets had last given Wilkerson an offer at the NFL Scouting Combine in February. On July 8, they made another offer, but it was for just four years and Wilkerson wanted six. Wilkerson went to Baltimore, where his agent, Chad Wiestling, lives, last weekend. As they watched the Orioles’ 4-2 win over the Angels at Camden Yards, the two talked about a deal with the Jets being unlikely. Wilkerson was prepared to sit out training camp then play the season under the $15.7 million franchise tag.

Then, things changed.

The Jets emailed Wiestling a new proposal Wednesday night. It was a five-year offer. Wilkerson had been seeking a six-year deal, similar to what the Eagles gave Fletcher Cox last month totaling more than $100 million. Now the two sides were getting closer.

On Thursday, Wilkerson and his representatives debated the new offer from the Jets. They responded by saying they would be amenable to a five-year deal, but the money had to be on par with Cox, whose annual average value was $17.1 million and received $36 million guaranteed at signing with $63 million in total guarantees.

Wiestling spent Thursday talking to Jacqueline Davidson, the Jets’ director of football administration and chief negotiator. Davidson said the Jets would make another offer Thursday night. That contract proposal landed in Wiestling’s inbox at 3:15 Friday morning. The money was more in line with what Wilkerson was looking for. The $86 million over five years gave him an average of $17.2 million per year, more than Cox. It had $36.75 million guaranteed at signing, more than Cox again, and $54 million in the first three years. The five-year deal also meant Wilkerson would sign his next contract at 31 years old if he plays the total length of the deal.

The two sides spent the entire day Friday hashing out the details with an eye on the clock. The deadline for all franchise tag players to sign a long-term deal was 4 p.m. on Friday.

Wilkerson went to the team’s Florham Park headquarters for his daily medical treatment. After suffering a broken bone in his right leg in Week 17 last year, Wilkerson has been rehabbing under the team’s trainer despite all that was going on with his contract.

Wiestling told Wilkerson to stick around after he was done in the trainer’s room in case a deal got done.

In the final hour before the 4 p.m. deadline, the two sides reached an agreement. Now, they had to get all of the paperwork signed and sent to the NFL and the NFLPA to get it approved by 4. Wilkerson went upstairs and signed the contract. Wiestling, operating out of his office in Maryland, read the deal over, signed it and sent it to the union. The Jets signed their side and sent it to the NFL.

At 4:30 p.m., the Jets tweeted the news that Wilkerson was signed long term.

Both sides celebrated. Wilkerson got the contract he had been seeking for two years. The Jets locked up one of their best players. The feeling on both sides is much different this weekend than last.