O'Sullivan, a five-time world champion, narrowly beat Liang 5-4 in a repeat of the 2009 final.
The 40-year-old had not played a World Tour match since losing to Barry Hawkins in April's World Championship.
Defending champion Kyren Wilson is out after a 5-2 defeat by Michael Holt, who faces O'Sullivan in the second round.
Follow all of the first round results from the Shanghai Masters here.
Ronnie O'Sullivan came back from 4-1 down to beat China's Liang Wenbo in the Shanghai Masters first round - his first match for five months.