The white-on-white uniforms are supposed to be Washington’s big-game ensemble. Coach Ron Rivera called for them late last year when the team upset the Steelers in Pittsburgh. He requested them when his squad dumped the San Francisco 49ers, again when it clinched the NFC East title with a win over the Philadelphia Eagles and once more in its lone playoff matchup, a first-round loss to the Tampa Bay Buccaneers now better known as “the Taylor Heinicke Game.”

Washington unveiled them a bit earlier this season, knowing it needed a critical victory in its first divisional matchup Thursday night. But while the big-game uniforms might have provided a bit of luck, the magic of Heinicke was the necessary spark as Washington defeated the New York Giants, 30-29, in a late-night thriller at FedEx Field. Washington’s win snapped a five-game losing streak against its rival and improved its record to 1-1, just in time to hit the road to Buffalo in Week 3.

“It wasn’t pretty, but we came out and got a ‘W,’ ” defensive end Chase Young said. “And that’s all that matters.”

The teams combined for 20 penalties for 161 yards, and the game hinged on the final five minutes, when Heinicke, starting in place of Ryan Fitzpatrick (hip), guided Washington on a pair of scoring drives, the last of which Dustin Hopkins sealed with a 43-yard field goal. That winning kick, fittingly, was aided by the final penalty of the game — an offside call on New York — that erased Hopkins’s first try, which sailed wide right.

“I was thankful they threw the flag, and that second one, man, I was so thankful for Hop,” Young said. “... I believe Hop deserved that. So, good job, Hop.”

Heinicke finished 34 for 46 for 336 yards, two touchdowns and a critical but ultimately irrelevant interception. The back-and-forth affair included five lead changes, including three in the final five minutes.

Washington’s offense opened with a pair of three-and-outs but hit its stride early in the second quarter, when Heinicke, on a quarterback sneak, picked up two yards to convert fourth and one.

A few plays later, Heinicke went to work with his star receiver. Terry McLaurin, on a shake route along the left sideline, gave a filthy head fake to Giants cornerback James Bradberry to gain separation and pick up 16 yards.

“The way Bradberry was playing the whole game, he was really looking to jump those routes — those routes over the middle, those seams,” McLaurin explained. “If I was running a post, he was looking to jump it. He’s an instinctual corner, but I knew I was just going to give him a little bit to the post and break out, and Taylor did a good job of putting it out there on the sideline so I could get away from [Bradberry].”

On the next play, McLaurin ran a skinny post route from the right side and broke inside away from Bradberry just as Heinicke launched a high pass in the end zone for an 11-yard score.

“When I saw the leverage on Bradberry, I knew we had the chance,” said McLaurin, who finished with a career-high 11 catches for 107 yards. “... We started rolling from there.”

But just as it looked as though Washington had turned a corner, the mistakes Rivera earlier described as “discipline” issues returned. A penalty here, a missed assignment there — often at critical junctures.

Such as the unnecessary roughness penalty on rookie tackle Sam Cosmi that stalled a second-quarter drive. Or the false start penalty on Troy Apke during Washington’s punt not long after.

Or the continued struggles of Washington’s defense, a unit that ranked second in total yards allowed last season but so far has been the team’s weakest group.

Third-year Giants quarterback Daniel Jones has often been its kryptonite, and for much of Thursday’s game, that didn’t change. In the first quarter, Jones sprayed passes around the left side and up the middle before waltzing into the end zone for a six-yard touchdown.

Then he broke loose for what could have been a 58-yard touchdown run that was ultimately trimmed because of a holding penalty on Giants wide receiver C.J. Board. Jones settled for only 46 yards on the play but was aided by the mistakes of Washington’s defense. Cornerback William Jackson III was flagged for pass interference just outside the red zone, and four plays later Giants kicker Graham Gano nailed a 23-yard field goal to give them a 10-7 lead early in the second.

“Defensively, I would say we played very similar to last week,” defensive tackle Jonathan Allen said. “We did enough to get the win, but moving forward, we have to be better.”

Washington responded on the subsequent drive, thanks largely to Heinicke’s 24-yard completion up the middle to tight end Logan Thomas that set the tone for a 12-play drive capped by a two-yard rushing touchdown by J.D. McKissic. New York overloaded the right side of the formation, and Heinicke audibled at the line.

He handed the ball to McKissic, who ran through the left side of the line, between tackle Charles Leno Jr. and guard Ereck Flowers, for the score just before halftime.

“It was going to be a pass play and they called timeout and they came back and there’s a three-man front and there were only about four or five people in the box,” Heinicke said. “So I was like, ‘Hey, if we don’t run and score a touchdown here, we don’t deserve to win.’ So I made the check, and it was a touchdown. I’m just glad Coach Rivera and [offensive coordinator Scott Turner] have the confidence in me to make that.”

But when Washington returned in the second half, momentum shifted and, worse, penalties piled up, extending Giants drives that should have ended on third and long.

In the third quarter alone, Washington was flagged five times for 43 yards. Safety Landon Collins was called for defensive holding on a third and seven that helped set up a Giants field goal, and cornerback Kendall Fuller was penalized for pass interference on a third and 13 that led to a 33-yard go-ahead touchdown catch by Darius Slayton.

And then Cosmi killed a second drive. Heinicke completed a six-yard pass to Adam Humphries that would have set up a fourth and one for Washington at the 23-yard line, prime position for “Riverboat Ron” to go for it in search of a touchdown. But a holding penalty on Cosmi sent Washington back to the 32-yard line and facing third and 17. It settled for a 49-yard field goal by Hopkins to get within 20-17.

“We’ve got to be a little more disciplined,” Rivera said. “That’s the biggest thing more so than anything else, I think. It’s unfortunate. We, as a group, have to understand and realize that there are certain things that we’ve got to be smarter about, and penalties are one thing. We can control that, for sure.”

Washington made it 23-20 with another field goal in the fourth, even as Jones continued to rack up rushing yards and nearly iced the game with a second deep touchdown to Slayton. (The ball slipped through his hands.)

But the magic of Heinicke returned — even after a pivotal mistake.

After orchestrating a go-ahead scoring drive with a 56-yard pass to McKissic and a remarkable 19-yard touchdown toss to tight end Ricky Seals-Jones, Heinicke’s attempt to seal the win turned disastrous. At his team’s 22-yard line, Heinicke threw a short pass right into the hands of Bradberry, and New York reclaimed the lead moments later with a 35-yard field goal by Gano.

Heinicke slammed his helmet to the ground and began to pace the sideline as the defense took the field.

“Oh, he was pissed,” Rivera said. “He was upset at himself.”

Redeeming Washington’s ugly play, however, was New York’s even uglier play. Heinicke led Washington back upfield in the final two minutes, getting close enough to give Hopkins a chance. Although the crowd quieted after his initial miss, it erupted once more as his second try sailed through the uprights.

Heinicke leaped from the sideline, where he sat crouched in suspense, and rushed the field to celebrate. In his seventh season, a player who nearly quit the game a year ago finally got his first win as an NFL starter — and gave his team reason to believe.

“He’s always ready for his moment, and I love guys who are always ready for their moment, always prepared,” McLaurin said. “... When you got a guy like that, you just want to continue to make plays for him.”