Cardiff made heavy weather of beating a side looking likely to return to Division Three after just one season at the higher level.
"It would have been a massive disappointment if we had lost and it was really too close for comfort," said Bluebirds boss Lennie Lawrence.
"We played some decent stuff but only in short spells and we didn't deal with their attacks very well. It was a spasmodic performance but they played with one up front and two nippy players behind and it did cause us problems.
"We had a very attacking midfield with Andy Campbell and Jason Bowen out wide and it meant we relied heavily on our back four to do a lot of tackling.
"I was pleased with Peter Thorne's goal as he was due one but I have always said form is temporary - class is permanent." Thorne bagged his first League goal since November and was clearly pleased to get on the score sheet.
"It was a big relief to score and it's a weight off my shoulders but the three points are more important," he said.
"We had a tough game against Coventry last Wednesday and there were a few tired legs out there but we weathered the storm.
"I want to be a more direct type of player and today I was able to do that rather than play with my back to goal which I have had to do in recent matches.
"As long as we are up at the end of the season I don't mind how many goals I score. Promotion is the most important thing." The Bluebirds only took seven minutes to open the scoring, when a cross from skipper Graham Kavanagh went to the far post where Chris Barker headed back into the danger area.
Thorne was first to react and smashed the loose ball into the back of the net.
City failed to capitalise on that and allowed the Robins to work themselves back into the game. Poor play by the home side led to the visitors grabbing an equaliser.
Jason Bowen failed to put in a challenge on Russell Milton, who was allowed to cross into the home penalty area. Spencer Prior and Andy Legg were ball watching and Robins' skipper John Finnigan was left in the clear to slam his shot into the far corner of the net.
City regained the lead with a carbon copy of Thorne's goal but this time it was strike partner Rob Earnshaw who found the net after Thorne had headed Kavanagh's flag kick back into the area.
The second half was poor quality with City barely able to string any decent passes together.
They were almost caught out in the final seconds when Prior and Scott Young gave substitute Damian Spencer a shooting chance, but his tame effort went straight at Neil Alexander and the Bluebirds held on for all three points.