Santa Clara: As the clock ticked down, coach Kyle Shanahan got doused with some Gatorade on a celebratory sideline for the San Francisco 49ers.

This win had been a long time coming.

CJ Beathard threw for 288 yards and two touchdowns and ran for a third score to lead the 49ers to their first win of the season with a 31-21 victory over the New York Giants on Sunday.

“You lose nine in a row, you learn to savour the moment and enjoy these,” Shanahan said. “It was tough work to get our first win and we got it. The guys knew how much it meant to me and I knew how much it meant to them.”

Beathard connected on an 83-yard TD to Marquise Goodwin and a 47-yarder to Garrett Celek in the second quarter as the 49ers (1-9) took advantage of another listless effort by the Giants (1-8) to win for the first time under coach Kyle Shanahan.

Beathard’s time as starting quarterback in San Francisco figures to be numbered after the team acquired Jimmy Garoppolo two weeks ago in trade from New England. Garoppolo has been learning the offence and could take over when the team returns from the bye in two weeks.

But for now, the Niners are happy to be able to celebrate a win as they rest up for the stretch run.

“I’ve been a part of a lot of wins with this franchise over the 11 years I’ve been here,” left tackle Joe Staley said. “This win felt just as good as winning the NFC championship. It was unbelievable.”

While the Niners could be making a quarterback change soon, this performance will only heighten the questions about whether the Giants will need to change coaches. Ben McAdoo has been under fire after a report this past week from ESPN that quoted an anonymous player as saying the players have given up on the season and don’t view McAdoo as a leader.

The Giants have not fired a coach during the season since 1976 when Bill Arnsparger was let go after a 0-7 start and replaced by John McVay, who had more success as an executive who helped build the 49ers dynasty in the 1980s.

“That doesn’t have anything to do with anything,” McAdoo said of his job security. “We have to find a way to win a game. We have to address what happened out here on the field today, take a look at the tape and be honest with each other.”

This was a historically bad matchup, marking the first time in 33 years that two teams with only one combined win met this late in a season. Then the teams committed three penalties before the second offensive play of the game.

The Niners were the only team to pick up their play from there, using the two big TD passes from Beathard to take a halftime lead and then dominating the second half.