Thurman - previously undefeated - had promised to send the 40-year-old Fillipino into retirement, but was knocked down in the first round before a thrilling fight went the distance.
"I knew it was too close," said American Thurman. "He got the knockdown so he had momentum in round one. This was a beautiful night of boxing."
The 30-year-old had been looking for his 30th straight win.
Two judges scored it 115-112 to Pacquiao, while the other gave it 114-113 to Thurman.
Pacquiao - a world champion at eight weights - was fighting for the 71st time in a stellar career that has seen seven defeats, but with four of those losses coming in his past 11 fights before the meeting with Thurman.
Afterwards, Pacquiao said he felt "blessed" and he will return to the Philippines to resume his work as a senator before deciding his next move.
"I think I will fight next year," he added.
Thurman had a height, reach, weight and age advantage over Pacquiao, but was chasing the fight from the beginning and started to bleed from his nose in the fifth round.
He recovered in the middle of the contest, but Pacquiao stormed back to take the last few rounds.
The Filipino could now face Britain's Amir Khan, though last week he denied claims that an agreement for a bout in Saudi Arabia was a already in place for November.
Khan claims the fight will take place in Riyadh on 8 November.
"I wish I had a little bit more output to go toe to toe," Thurman told US broadcasters. "I felt like he was getting a little bit tired, but he did have experience in the ring. My conditioning, my output, was just behind Manny Pacquiao. It was a great night of boxing. I'd love a rematch.
"I want to thank the fans. I want to thank everybody for coming out. Manny Pacquiao is a great, truly great champion."