The 13-year-old elephant, who was kept inside a dark shed at Jyotiba Temple, will now be moved to a wildlife centre.
McCartney, 70, and Anderson had pleaded with India's forest minister Dr Patangrao Kadam for the animal's release.
"I have seen photographs of young Sunder, the elephant kept alone in a shed at a temple and put in chains with spikes. Years of his life have been ruined by keeping him and abusing him in this way. Enough is enough. Get Sunder out," McCartney had written.
The release of Sunder was the result of a three-month campaign by PETA (People for Ethical Treatment of Animals), of which both McCartney and Anderson are supporters.
"The difference between Sunder's cruel life in chains at the temple and his new journey to freedom, love and care is like night and day. We are grateful to the Forest Minister for agreeing to liberate Sunder and let him enjoy things that are natural and important to him for the first time in his life," said a PETA spokesperson.