Trailing by 14 in the first half, Stanford looked vulnerable without point guard Daejon Davis. But the Cardinal rallied behind Marcus Sheffield, an unlikely hero.

Bryce Wills sank the decisive basket with 13 seconds left as the Cardinal knocked off USC 79-76 Wednesday night at Maples Pavilion.

Coming off a 23-point loss at Oregon on Sunday, Stanford badly needed a victory. The Cardinal got it, pushing their record to 13-11 overall and moving into a four-way tie for sixth place in the Pac-12 with a 6-6 mark.

“This game was a redemption game for us,” Wills said. “We had to get back on track.”

The Cardinal were without Davis for the second straight game because of an injury in the Oregon State game. A year ago, Davis hit a buzzer-beating 50-foot shot to beat USC 77-76 at Maples.

Just as Oregon did in its 23-point win over Stanford on Sunday, the Trojans took advantage of his absence by applying a pressing defense.

The Cardinal made just four of their first 17 field goal tries and eventually fell behind 34-20. But Stanford rallied and led 64-58 with 7 ½ minutes left. USC (13-12, 6-6) took the lead three times after that, but the Cardinal were not to be denied.

“Coach always tells us to be warriors, keep fighting, keep grinding, and don’t keep your head down for too long,” Wills said. “We fought back like warriors.”

Haase said, “When we got down 14, there was a tight-knit group that was still together. We knew we weren’t playing very well.”

Sheffield, a reserve forward averaging 4.6 points a game, sank his fourth 3 of the game with 44 seconds left to cut USC’s lead to 76-75 before Wills’ dramatic drive.

“In the timeout, the coaches told me to get downhill as fast as I could and look for the corners if the defense sucked in,” Wills said. “Nobody sucked in, and I went for the layup and got fouled.”

He missed the free throw, but after USC’s Bennie Boatwright missed a 16-footer, Wills grabbed the rebound. He was fouled and sank two foul shots with a second left for the final margin.

Stanford’s KZ Okpala shook off a cold-shooting first half to score 18 points before fouling out with 1:10 left.

Sheffield had 16 points, while Josh Sharma added 14 and nine rebounds for Stanford. Wills had 11 points and Oscar da Silva 10.

Haase said of Sheffield, “What he brings is stability and an old-man attitude, and I mean that in a real positive way. He’s been around for four years. His nature anyway is stable and even keeled. When we’re struggling out there, the guys look at him. He’s just as even keeled as he could be.”

Boatwright, who has been plagued by injuries the last two seasons, scored 19 to lead USC (13-12, 6-6). Jonah Mathews scored 16, and Nick Rakocevic had 15 points and 11 rebounds. Kevin Porter Jr. added 10 points.

Tom FitzGerald is a San Francisco Chronicle staff writer. Email: tfitzgerald@sfchronicle.com Twitter: @tomgfitzgerald