A sell-out crowd of 15,758 for the noon kick-off saw Cardiff take a 21st minute lead when Joe Ralls was allowed space to deliver a low cross from the left of the box and Immers swept home a low drive from 12 yards at the far post.
Any doubt about the result was removed seven minutes from time when O'Keefe headed home from close range after a Tom Lawrence shot had been tipped onto the bar by Richard O'Donnell.
With Bruno Ecuele Manga outstanding at the back, Cardiff repelled Bristol's attacks and emerged worthy winners.
The visitors posed the first threat when Immers volleyed wide at the near post on five minutes and were the quicker to settle.
Nathan Baker headed over from a Lee Tomlin corner on 16 minutes as Bristol began to get into their stride.
Then came Immers' goal, which was not the first time the hosts had looked vulnerable at the back, and Cardiff defended their lead well until the break.
The biggest moment of anxiety for David Marshall came from a 28th minute volley from Jonathan Kodjia, but the angle was narrow and the Bluebirds goalkeeper beat the effort away.
Anthony Pilkington, operating as a lone striker for Cardiff, beat the offside trap on 38 minutes and advanced menacingly, only to see his low shot from 25 yards palmed wide by the diving O'Donnell.
Bristol were finding it hard to get behind a well-organised Cardiff defence and Kodjia, like Pilkington in a lone role up front, was unable to hold the ball up effectively.
The home side's frustration was demonstrated when Tomlin collected a booking for dissent as the players left the field at the break.
Cardiff were forced into a change at the start of the second half, with Sean Morrison replacing right-back Lee Peltier. Morrison slotted into central defence with Matt Connolly moving across to the right.
Bristol made a tactical switch pushing Tomlin up alongside Kodjia, who frustrated home fans by delaying his cross when behind the defence on 50 minutes.
Tomlin was the biggest threat for Bristol City and his deflected 55th minute shot brought a smart save from Marshall.
The Cardiff keeper was in action again on 70 minutes, diving to his right to palm away Tomlin's free kick from 30 yards.
Bristol were on top for the first time and Scott Golbourne's shot from distance flashed just wide.
But O'Keefe's goal eased any late pressure on Cardiff, who continued their impressive move towards the play-off places as a late header from substitute Aaron Wilbraham passed harmlessly over Marshall's crossbar.
Bristol City (4-4-1-1): O'Donnell; Little (Ayling 64), Flint, Baker, Golbourne; Freeman, Pack, Bryan, Tomlin; Reid (Wilbraham 64); Kodjia (Agard 79 ).
Cardiff City (4-4-1-1): Marshall; Peltier (Morrison 46), Ecuele Manga, Connolly, Malone; Lawrence, O'Keefe, Ralls, Whittingham (Noone 70); Immers (Dikgacoi 83); Pilkington.
Referee: Graham Scott (Oxfordshire)
Attendance: 15,758