Allen began the second session of the match 5-4 ahead but found himself trailing 7-6, before moving clear.
The number 11 seed will face world number six John Higgins in the second round on Friday and Saturday.
"I didn't really deserve to win. I thought Jimmy played the better, more positive snooker," said Allen.
"It was a tough two days for me but I'm over the moon to come out on the right side of the result."
Sussex player Robertson was aiming to win a match at the Crucible for the first time and started strongly on Monday night as he came from 5-4 down to take three of the first four frames with breaks of 62, 66 and 54.
Allen, a semi-finalist in 2009, won frame 14 with a run of 60 for 7-7, then took the next by potting blue and pink.
World number 39 Robertson made a 66 for 8-8 and he had the first scoring chance in frame 17 but made just 17.
Allen hit back to take it then clinched victory in the 18th with a break of 97.
"I could have easily lost that first session 6-3 or 7-2 but somehow managed to come out 5-4 up. I pinched a few frames that I shouldn't have. Jimmy started like a train and put me under all sorts of pressure," added Allen after his success.
"He came out positive tonight as well but the one thing I don't lack is bottle. It would be nice to have a bit of form to go with it.
"I can't keep playing like that or I'll get beaten. Maybe scraping through that match will spur me on."
The Antrim cueman has had a disappointing season by his standards, reaching just one ranking event quarter-final.
"I've won matches in the big invitation events this season so financially I've been ok. But in the ranking events I haven't been winning anywhere near enough matches."
Northern Ireland's Mark Allen struggled past Jimmy Robertson 10-8 in the first round of the World Championship at the Crucible Theatre in Sheffield.