Yuvraj, playing only his third Test, hit 112 before he was last man out as India recovered from a precarious 127 for six to make 287 on the opening day at the Gaddafi stadium on Monday.
Pakistan, looking to level the three-match series after losing the first Test at Multan by an innings and 52 runs last week, were 61 for one in reply at close.
Taufiq Umer was the batsman out, bowled by Laxmipathy Balaji for 24, but Imran Farhat (25) and Yasir Hameed (four) saw out a good day for Pakistan.
Gul, who turns 20 next week, destroyed India's top order in a hostile spell of 12 overs after stand-in captain Rahul Dravid won the toss and elected to take first strike on a greenish wicket.
Yuvraj, playing only because regular captain Sourav Ganguly was injured, engineered India's recovery which saw the last three wickets add 140 precious runs.
Irfan Pathan, who joined Yuvraj at 147 for seven, hit a career-best 49 in an eighth-wicket stand of 117.
Yuvraj, coming into bat with the tourists reeling at 94 for four, hit 14 boundaries and two towering sixes in his century before holing out to deep mid-wicket off leg-spinner Danish Kaneria.
"I feel great and proud of myself because when I went in the team was in trouble and when you perform when the chips are down, it is something special," Yuvraj said.
"This century means a lot to my career. I am not worried about my place in the team because whatever cricket I get I want to perform. We have a decent total on the board. There is something in the pitch for the bowlers and it is now up to the bowlers to get them out cheaply."
Before Yuvraj came into his own, Gul claimed the prize wickets of Virender Sehwag and Sachin Tendulkar in successive overs and the vital one of Venkatsai Laxman to leave India at 107 for four by lunch.
Dravid resisted for nearly two hours to score 33 before Gul claimed two more wickets to better his previous best of 4-58 against Bangladesh at Multan last year.
Gul had Dravid caught in the slips soon after lunch and then trapped Parthiv Patel leg-before without scoring.
Gul did not bowl a second spell due to cramps in his right leg, but by then he had done enough to motivate his teammates to fight back after a disappointing show in the first Test.
Express pacer Shoaib Akhtar took his first wicket in the series when he had Ajit Agarkar caught behind by wicketkeeper Kamran Akmal.
Kaneria broke the Pathan-Yuvraj stand by snapping a return catch off Pathan before Mohammad Sami had Balaji caught behind for nought.
It was Pakistan all the way in the morning session.
The first break was provided by Sami who had Aakash Chopra leg-before in the second over.
Sehwag, who hit an epic 309 in the Multan Test, appeared to continue the same form when he began by slashing Akhtar for a six over point.
But Gul forced an edge off Sehwag's rampaging blade to carry to Akmal after the opener had made a rapid 39 with six boundaries and a six.
In his next over, Gul trapped Tendulkar leg-before for two to leave India at 75 for three.
Laxman, who made 11, edged an outswinger off Gul to second slip where Taufiq took a low catch to give Gul three wickets off 26 deliveries.
Pakistan was forced to make four changes after injuries to Abdul Razzaq (back problem), Shabbir Ahmed (shin) and wicketkeeper Moin Khan (groin) in addition to dropping out-of-touch off-spinner Saqlain Mushtaq.
Their places were taken by left-handed batsman Asim Kamal, Gul, reserve 'keeper Akmal and Kaneria.