Rankin, who signed from Hibernian in May 2011 and has made 117 appearances for the club, has been a key member of Jackie McNamara's squad - playing in 29 of the 31 games so far this season
United manager McNamara told the club's website: "This is great news for the club and fans.
"John wanted to stay here and continue to enjoy his football and we are delighted with the job he is doing. We want our young players to learn good habits and both on and off the park John leads by example.
"He is a fans' favourite and securing his extension shows the fans we are intent on keeping our players and taking the club forward.
"The fans will be thrilled with this news and I am delighted that he will be part of my squad for a further two seasons."
Rankin said: "The last three seasons have been the most enjoyable period of my career and I see the potential here right now and I want to be a part of that.
"The supporters are so encouraging and whilst that is important for the youngsters at the club it is also nice for us more experienced players.
"There is a positive vibe around Tannadice and we can achieve things in the near future here. We have shown progress over my time here and I think we are now ready to go to the next level."