Pakistan President Pervez Musharraf was on hand for an hour to watch the run feast after Inzamam-ul Haq won the toss and elected to bat in the day-night international on Tuesday.
Afridi and Hameed put on 138 for the first wicket and Pakistan moved to 191 for one by the 29th over, before left-arm seamer Ashish Nehra hit back with two wickets off successive balls.
Nehra, who was retained in the side despite being ruled out by the team management on Monday due to an ankle injury, clean bowled Inzamam for 29 and then trapped Moin Khan leg-before first ball.
Nehra finished with 3-44 as Pakistan slipped to 249 for five, but Shoaib Malik and Abdul Razzaq plundered 50 runs in the last five overs to steer Pakistan past the 300-run mark.
Malik remained unbeaten on 30 while Razzaq scored a rapid 31 not out off just 19 deliveries.
India, who lead 1-0 in the five-match series, face a stiff target of more than six runs an over under lights against the express pace of Shoaib Akhtar, playing his 100th One-dayer.
The first match at Karachi on Saturday ended as the highest-scoring One-dayer in history with Pakistan making 344 for eight in reply to India's 349 for seven.
Afridi, selected for the first time since Pakistan's World Cup loss to India on March 1 last year in South Africa, smashed 80 off 58 balls with the help of four sixes and 10 boundaries.
Hameed, the more circumspect of the two, batted till the 35th over to make 86 before he was run out following a mix-up with Inzamam.
Some 19,300 home fans at the heavily-guarded Pindi stadium came alive from the start as Afridi and Hameed plundered 81 runs in the first 10 overs.
The pair brought up 100 by the 13th over before Afridi's brilliant knock ended tamely when he missed a heave off part-timer Yuvraj Singh and was bowled.
Yuvraj, bowling gentle left-arm spin, gained another success when Yousuf Youhana played a juicy half-volley on to his stumps.