Aron Cohen added 14 points for Penn (8-14, 3-2 Ivy) in a game that saw 52 fouls called, including three technicals.
Neither team had more than a 5-point lead over the last seven minutes and the Quakers took a 64-61 advantage on a three-point play by Egee with 1:42 left. A layup by Noah Savage cut the lead to 64-63 at 1:10 before Cofield made his two foul shots with less than 10 seconds remaining.
Princeton was then called for a technical foul before inbounding the ball, and Jack Eggleston and Egee each made a foul shot to clinch the win.
The victory extended Penn's Ivy League home winning streak to 24 straight.