A penalty from replacement James Hook with three minutes left preserved the British and Irish Lions' unbeaten record as they scraped a fifth win of their South Africa tour at a wet and windy Newlands.
But they were pushed all the way by a hugely committed Western Province side who made light of their missing Springboks to give the visitors a major scare.
Tries from Tommy Bowe, his fourth of the tour, and Ugo Monye helped the Lions to an 18-12 half-time lead after trailing 9-6.
But after Martyn Williams scored a third try 15 minutes into the second half, the hosts rallied to level the scores with 17 minutes left as full-back Joe Pietersen scored in the left corner.
The Lions endured some shaky moments as a first defeat of the tour loomed, but their dominant scrummage pulled them out a hole.
Referee Mark Lawrence awarded them another penalty from a scrum five metres into the Western Province half in the 77th minute, and Hook - on for the limping Rob Kearney - held his nerve superbly to steer it through the posts despite the swirling wind.
While the tourists will take comfort from the outcome, and keeping their try-line intact, it was hardly the commanding Saturday display head coach Ian McGeechan had hoped for a week before the first Test.
Mercifully, a series of storm showers that lashed Newlands, in the shadow of a cloud-covered Table Mountain, ceased before kick-off, but the players still had to contend with a gusting wind.
After a dismal opening period notable only for repeated bouts of aerial ping-pong, two well-struck penalties from Stephen Jones, in response to an early one from Western Province fly-half Willem de Waal, put the Lions 6-3 ahead.
Monye benefited from Bowe's attack to score in the left corner
The tourists won a free-kick and a penalty from the opening two scrums, and a third Jones penalty from 42m fell narrowly short in the wind.
But the tourists were struggling to inject any rhythm into their attacks as the hosts enjoyed a period of ascendancy to take a brief 9-6 lead.
De Waal fired over a superb left-footed drop-goal from 40m in the 18th minute before full-back Pietersen, uncertain under the high ball in defence, joined the attack to land an easier drop from in front of the posts.
The Lions wasted no time in rectifying the situation, however, scoring their opening try within a minute, from their first decent attack of the half.
Number eight Andy Powell made a charge, Williams popped up a sweet pass and Rob Kearney delayed his pass to Bowe, on the wing, perfectly.
The Monaghan man still had plenty to do, but caught the ball behind him and pirouetted out of a tackle before fending off another to score.
Jones missed the conversion from the touchline, and Pietersen was off target with a snap drop-goal that might have regained the lead for the hosts.
But the Lions stepped up a gear and scored a second try in the 34th minute after patiently working the ball through nine phases.
Again it owed everything to Bowe, who cut a wonderful angle off his right wing into the line before stepping inside one man, fending off another and then looping an inviting pass for Monye to sprint onto and dive into the left corner.
Jones landed the extras for an 18-9 advantage, but De Waal's second penalty, with the last kick of the first half, kept the hosts in touch at the interval.
De Waal's powerful boot kept the Lions pinned back on several occasions, and after missing a penalty attempt from inside his own half, he banged over another to reduce the deficit to three points.
But the tourists responded with a third try, a patient series of pick-and-goes from the pack rewarded when Williams spun out of a tackle to dot down in the left corner.
Jones again failed to convert from the touchline, but at 23-15 up, the platform seemed set for another late Lions onslaught.
Hook's late penalty snatched the win for the relieved Lions
Western Province had other ideas. De Waal's fourth penalty on the hour brought the hosts to within a score, and when it came five minutes later it was rapturously greeted by the home fans in the 34,000 crowd.
Lock Anton van Zyl sent Riki Flutey the wrong way with a lovely dummy as he charged into the Lions 22, and as the ball was swept along the line, Pietersen found himself with room to dive over in the left corner.
De Waal was unable to convert from the touchline, however, and the Lions endured some anxious moments as the clock ticked down.
Hook missed a long-range penalty, Powell was penalised for not using his arms in a thundering hit on flanker Duane Vermeulen, and Monye was penalised for taking a quick line-out to himself but not throwing it five metres.
But to their credit they refused to buckle as the hosts went in pursuit of a famous victory, and Hook's late penalty saw them prevail, just.
Western Province: Joe Pietersen, Tonderai Chavhanga, Morgan Newman, Peter Grant, Gcobani Bobo, Willem De Waal, Dewaldt Duvenage; Wicus Blaauw, Tiaan Liebenberg, Brok Harris, Martin Muller, Anton Van Zyl, Pieter Louw, Duane Vermeulen, Luke Watson (capt).
Replacements: Hanyani Shimange, JD Moller (for Blaauw, 75), De Kock Steenkamp, Zandre Jordaan, Conrad Hoffman, JJ Engelbrecht, Gio Aplon (for Chavhanga, 37)
Lions: Rob Kearney, Tommy Bowe, Keith Earls, Riki Flutey, Ugo Monye, Stephen Jones, Harry Ellis; Andrew Sheridan, Matthew Rees, Phil Vickery (capt), Donncha O'Callaghan, Nathan Hines, Joe Worsley, Martyn Williams, Andy Powell.
Replacements: Ross Ford (for Rees, 56), Euan Murray (for Vickery, 60), Simon Shaw (for Hines, 56), Tom Croft (for Worsley, 69), James Hook (for Kearney, 66), Not used: Shane Williams, Gordon D'Arcy.
Referee: Mark Lawrence