BOULDER — Colorado suffered a heartbreaking defeat to Southern California Friday night that was made all the more painful with the news that starting quarterback Sefo Liufau was lost for the remainder of the season with a fractured left foot.

Liufau suffered a Lisfranc injury being sacked on the last play of the first quarter when the pile fell on him. He will be out for six to eight months and will likely have surgery early next week.

Colorado was leading 7-3 when Liufau was replaced by backup Cade Apsay, who led CU to a 17-6 halftime lead, but the Trojans scored 21 unanswered points and prevailed 27-24 in Colorado’s final home game of the season.

Liufau staggered as he attempted to walk off the field after he was hurt. Later he pounded a sideline table in anger after being examined by the CU medical staff.

“You really care for him,” coach Mike MacIntyre said. “First of all, you want to make sure he’s OK, make sure Mom’s OK. Then go the next step, make sure academically he doesn’t fall too far behind (because of surgery). He’s a business major, our school is tough. Then get him on the road to coming back.”

Apsay, a redshirt freshman from Canyon Country, Calif., completed 18 of 23 passes for 128 yards and two touchdowns without a turnover.

“I think it was OK,” Apsay said of his performance. “If I were to give it a grade, it would be average like a C, because there was a lot of things I cold do better and execute better — make better decisions, make better checks.”

Liufau watched much of the game with crutches on the sideline with a big ice pack on his foot.

“He told me, ‘Stay calm, I know you are prepared, so to out there and execute and play football,’ ” Apsay said.

Senior receiver Nelson Spruce tied Scotty McKnight’s school record for career touchdown receptions (22) in his last game at Folsom Field, but now he will be without the quarterback who threw most of those passes.

“I saw him limping around and I was like, ‘Oh, he’s all right, he’ll come back,’ ” Spruce said. “Then he got taken to the locker room and Cade had to come in … He (Apsay) came in and did his job and even more, so I am excited to see what he can do these next two weeks.”

Colorado fans must be asking what would have happened if Liufau hadn’t gotten hurt, and what happens now with him gone. The Buffs finish the season with games at Washington State and Utah.

Colorado’s first four possessions of the second half ended with a punt, a Christian Powell fumble deep in CU territory, a blocked field goal and a punt. The Buffs finally scored their only points of the second half on a 2-yard touchdown pass to fullback George Frazier with 6:13 left in the game that was set up by a 45-yard punt return by Spruce.

Tying McKnight’s record was little solace for Spruce after yet another close loss to a heavily favored foe.

“I was talking this week about getting that signature win, that would be like my memorable moment here,” Spruce said. “It was right there, but it’s kind of been the story of the season, not being able to finish. Being my last (home) game, it was definitely one that I wanted that much more. It does hurt.”

Sacks proved to be CU’s undoing. After Liufau was injured on one, Apsay would be sacked five times, one of the reasons Colorado had only 83 yards of offense in the second half.

Two mistakes hurt the Buffs dearly. On USC’s first possession in the third quarter, USC had a third-and-goal at the 8-yard line. Derek McCartney sacked USC quarterback Cody Kessler but Jimmy Gilbert was called for offside. Kessler hit Jaleel Pinner on the next play for a 4-yard touchdown that made it 17-13. That was a four-point mistake in a three-point loss.

Then Christian Powell fumbled on the first play of the ensuing CU possession, giving USC the ball on the Buffs’ 34. USC scored seven plays later on a 4-yard pass to tight end Taylor McNamara, giving the visitors a 20-17 lead with 2:32 remaining in the third quarter.

“We fumbled the ball to them, gave them that,” MacIntyre said. “We line up offsides on a big third down play, which would have made them kick a field goal, they score on the next play. And not having Sefo out there hurt us a little bit at times.”

John Meyer: jmeyer@denverpost.com or @johnmeyer

CU attendance:

Attendance at Colorado home games has lagged since 2011, but attendance actually shows an increase this season. The numbers: