Glasgow rallied when they were losing 19-15 early in the third quarter thanks to an outstanding try from wing substitute Tommy Seymour.
That score was converted by another sub Ruaridh Jackson, who added a penalty. Scott Wight and Mark Bennett both kicked two penalties for the hosts.
Cardiff fly-half Rhys Patchell contributed his side's points with four penalties and a drop-goal.
The pitch was in perfect condition but half an hour before kick-off the local dry spell ended with heavy rain which affected handling in the early stages.
Referee Dudley Phillips was hot on the tackle, handing out early penalties.
Glasgow stand-off Wight was first to register, followed by a brace of long-range efforts from Patchell - which put the visitors ahead.
However, Glasgow levelled in the 11th minute, this time centre Bennett finding the target from the centre spot.
The Glasgow cause suffered a bad blow as the first quarter ended with two substitutions required in as many minutes.
First, winger Byron McGuigan limped off replaced by the experienced Seymour.
But the second injury looked serious. Captain and lock Al Kellock had to be removed by stretcher after a notable delay - with last season's Scotland Under-20 captain Jonny Gray taking his place.
The young Cardiff side were showing up well with a persistent hand denying Glasgow winger Sean Lamont after he cut through the centre.
However, the visitors went behind to a Wight penalty after 33 minutes, after centre Owen Williams had tripped Lamont as he hared after his own kick, earning a yellow card.
Two minutes from the break Wight missed a penalty from the left, but when one was awarded on the other side right-footed Bennett slotted home to send his side in leading 12-6.
Conditions continued to dictate play in the second half with difficult footing now adding to handling problems.
Referee Phillips continued to find fault with Glasgow at the tackle.
Three penalties were awarded to Cardiff between the 51st and 56th minutes. Patchell brought equality by kicking the first and third while the second from deep in his own half lacked only accuracy.
When Bennett missed a penalty, only for Patchell to nudge Cardiff ahead with a drop-goal, the match seemed to be in the Welsh side's grasp.
However in the 68th minute, Seymour cut clean through the Cardiff midfield to touch down in the right corner from where Jackson converted to put his side into a 19-15 lead.
Four minutes later flanker Macauley Cook was the second Cardiff man to see yellow and Jackson kicked the penalty.
Cardiff staged a late push but Glasgow held out under their posts.