The tourists achieved the sixth highest successful chase in history when they surpassed the target of 377 runs in the post-lunch session of the fifth day's play in Pallekele, finishing on 382-3.
Skipper Misbah-ul Haq made 59 not out, smashing the winning six off Jehan Mubarak to end his nation's long winless streak in Sri Lanka where they had lost the last three series in 2009, 2012 and 2014.
"This is such a big victory for us," said a delighted Misbah as Pakistan jumped three places to number three in the official rankings behind South Africa and Pakistan.
"We had lost some Tests in Sri Lanka earlier because we panicked. We just wanted to bat calmly this time.
"This series win means a lot to me after we did not fare well in the last three series in Sri Lanka."
It was the first time a visiting team had scored more than 300 runs in the fourth innings to win a Test on Sri Lankan soil.
Sri Lankan captain Angelo Mathews said he expected his team to have defended the 377-run target.
"That was not a small total to get, so obviously I am very disappointed," he said. "I thought we were sitting pretty when we gave them 377 to win.
"It was a good game of cricket, but Pakistan played better than us and deserved to win. There may have been a bit more turn towards the end, but there was nothing in the wicket for the seamers over the last couple of days."
Mathews said the team were trying to overcome the absence of batting greats, the retired Mahela Jayawardene and Kumar Sangakkara, who opted out of the final Test.
Younis, who made his 100th Test appearance in the second match, ended the game just 19 runs away from surpassing Javed Miandad's tally of 8,832 runs to become Pakistan's leading scorer in Tests.
Pakistan added 25 runs to their overnight score when they lost the wicket of Shan Masood, who was stumped by Dinesh Chandimal off Tharindu Kaushal for 125.
The Kuwait-born left-hander's maiden Test century came during a third-wicket stand of 242 with Younis after Pakistan had been reduced to 13-2 on Monday afternoon.
Misbah said Younis had told the team a win was possible because the wicket was not providing assistance to the bowlers.
"Both Younis and Masood took the game away from Sri Lanka. And Yasir (Shah) has been so good in this series. I am glad the youngsters are doing so well for the team."
Leg-spinner Yasir was named man of the series for his 24 wickets in the three Tests. Younis was adjudged the man of the match.
The 37-year-old Younis, who came to bat after the fall of the second wicket, remained rock solid at one end during a seven-hour vigil in which he hit 18 boundaries.
Younis' five hundreds in the fourth innings -- in a career tally of 30 -- are the most by any batsman.
Misbah provided able support during a 127-run stand with Younis, mixing caution with aggression which fetched him eight fours and a six.
Sri Lanka missed the experience of left-arm spinner Rangana Herath, who was not selected, as young off-spinner Kaushal was hammered for 153 runs in his 31 overs.
Pakistan had won the first Test in Galle by 10 wickets and Sri Lanka took the second in Colombo by seven wickets.
The two teams will now play a limited-overs series of five one-day internationals, followed by two Twenty20 games, from Saturday.