Late Sunday night, Kyle Shanahan found himself at the midpoint of two urgent problems with contradictory solutions. The moment defined the extreme end of a modern NFL quandary: What is the line for when a trailing coach should prioritize keeping the ball away from an opposing offense over taking the lead?

Shanahan’s San Francisco 49ers trailed the Green Bay Packers by six points in the fourth quarter. The clock was running below one minute after they gained a first down at the 12-yard line. The 49ers had all three of their timeouts remaining. The Packers had none. A gassed Green Bay defense stood on the field. Aaron Rodgers stood on the other sideline, and from the Niners’ perspective, he may as well have been sitting on a pale horse.

The 49ers had total control of the clock but only partial control of the score. Exerting control over one meant losing control of the other. They needed to score quickly. They also needed to score with as little time as possible to prevent Rodgers from performing a habitual act of magic.

We know what happened: The 49ers took their next snap with 43 seconds remaining (the clock was running), with the play clock showing 12 seconds. Jimmy Garoppolo rifled a slant to Kyle Juszczyk, who caught the ball at about the 2-yard line and barreled into the end zone with 37 seconds remaining. The extra point gave the 49ers a 28-27 lead with 37 seconds remaining. Rodgers marched the Packers 42 yards in six plays, all the yardage covered over two passes to Davante Adams, in 34 seconds. Mason Crosby kicked a game-winning field goal that cleared after the clock hit zero.

In some circles, Shanahan’s decision not to drain more clock was harshly criticized. Analyst Warren Sharp called it “egregious.” Shanahan did make some detrimental coaching decisions during the game, including during the endgame. But scoring too quickly was not necessarily one of them.

It would have been ideal to score with less time remaining, of course, but the 49ers could only manipulate the game to a certain degree. They may have controlled the clock, but the Packers’ defense had control of whether they could score. Trailing by a touchdown, Shanahan would have taken too large of a risk had he whittled the clock before scoring a touchdown.

The final sequence began with a clearly savvy choice by Shanahan. When the 49ers gained a first down inbounds at the 12, Shanahan allowed the clock to run, even calling for his offense to huddle to drain more clock.

The 49ers snapped the ball with 43 seconds left, with 12 seconds on the play clock. The screenshot made social media rounds as an indictment of Shanahan. But it only looks like an indictment because we know what happened. Shanahan didn’t know the 49ers would score on that play, so he had reason to preserve the clock.

This morning, the 49ers’ priority appears to be keeping Rodgers off the field. That was an important imperative — in the current NFL scoring climate, especially with an elite quarterback on the other side, the ability to score last is nearly as determinative as the ability to score. But the 49ers’ priority was still scoring a touchdown, and snapping with 43 seconds left rather than about 35, in the absence of certainty they would score, still helped that goal.

A typical NFL play takes six seconds. Given their three available timeouts, the 49ers could confidently assume they could run seven more plays, six at the least. At the moment of the snap, Shanahan had incentive to preserve the potential to run all of those.

The 49ers could still get another first down inside the 2, which helped their play-calling — with enough time remaining, the Packers would have to defend both the goal line and the 2. But the 49ers would only access that advantage if enough time remained on the clock to run additional plays. If the 49ers used the entire play clock on first down, they would have effectively lost the chance to pick up that first down — and the chance to make Green Bay defend the 2-yard line.

The 49ers held the massive advantage of holding three timeouts, which not only allowed them to control the pace but also opened Shanahan’s entire playbook, forcing the Packers to defend the run as well as the pass. Once the 49ers used those timeouts, it would become harder for them to score. Scoring fast would allow Rodgers time, but scoring slow would make it more difficult for the 49ers to take the lead in the first place.

And taking the lead in the first place still mattered most, even more than sidelining Rodgers. By running the clock down, even with all of his timeouts, Shanahan could have cost the 49ers the chance to run two more plays, and every play gave the 49ers an additional chance to score the touchdown. Win probability models are imperfect, but even with first down on the 1-yard line and about 30 seconds left, those models still give teams trailing by six points about coin-flip odds to win.

Given the math and gameplay involved, snapping at 43 seconds seems like the sweet spot — it preserved the possibility to run six or seven plays while still draining the clock. He may have played it just right, and if he erred, the margin was certainly not egregious.

If Shanahan did commit a strategic blunder during the endgame, it came on the kickoff. Shanahan let kickoff specialist Mitch Wishnowsky blast a touchback into the end zone. By kicking the ball deep but keeping it in play, Wishnowsky would have forced the Packers to exhaust several crucial seconds. Yes, a kickoff in play gave Green Bay a chance at a big return. That small risk probably would have been worth the potentially pivotal benefit of draining about four seconds. Remember: Rodgers spiked the ball on the Packers’ last play with three seconds left.

The 49ers may not have needed the desperate final seconds had Shanahan not punted in the first half at midfield on fourth and one, a decision that truly is egregious. (Not for nothing, but Packers Coach Matt LaFleur should be excoriated for reaching the final moments of the game with zero timeouts. He used them on a failed challenge early in the fourth quarter after a 16-yard Niners gain and twice to avoid delay of game in the fourth quarter.)

As it stood, the 49ers had the game won, until they didn’t. They lost because of the brilliance of Rodgers-to-Adams. They lost because they could only control so much. It was the kind of game that could be discussed and debated forever, with no last word. As Rodgers might say, how can you not be romantic about that?