Tahir has had a dramatic effect on Hampshire's fortunes this season since making his club debut in July, helping transform the Rose Bowl-based side from seeming certainties for relegation to having an outside shot at becoming county champions for the first time in 35 years.
Before the final round of matches, which started on Wednesday, Tahir had taken 36 wickets in six Championship fixtures at a meagre average of just over 17 apiece.
It looked as if he would miss the last match of the season, away to Nottinghamshire, the First Division leaders, when he was recalled for pre-season training by the Titans before the South African franchise relented and allowed him to play at Trent Bridge.
"This is fantastic news for Hampshire cricket and all our members and supporters," Hampshire chairman Rod Bransgrove said.
"'Immy' has made a massive contribution to Hampshire cricket since his arrival in July and he has become a real favourite both in the dressing room and with our members and spectators.
"I am extremely pleased that he has chosen to commit himself to Hampshire for the next two seasons - and I am sure that he will continue to be one of the most potent and successful spinners on the county circuit."
Tahir, 29, added: "I am very grateful to Hampshire for giving me the opportunity to continue to play for this amazing club."
News that Tahir would be staying with Hampshire came on the same day the county revealed that England Under-19 all-rounder Liam Dawson would be staying at the Rose Bowl for a further three years.
Dawson has enjoyed a fine first full county season, with the 18-year-old left-arm spinner and middle-order batsman nominated for the Cricket Writers' Young Cricketer of the Year award, won this month by England's Ravi Bopara.
"I'm delighted to have signed a new three-year contract with Hampshire," said Dawson, who effectively counts as a homegrown product after being born and brought-up in the neighbouring county of Wiltshire, which does not have a first-class cricket team.
"The club have shown a lot of faith in me and I hope to repay with good performances."
Acting team manager Giles White added: "The long-term deal Liam has been offered reflects how highly he is regarded.
"We see him playing a big part in Hampshire cricket's future. I can't think of a more exciting young prospect in the country."
Hampshire's Tahir-inspired push for the title has come in their first season since former captain and Australia leg-spin great Shane Warne left the county after retiring from first-class cricket.