It was a second Gold Cup triumph for the 16-time champion jockey under Jonjo O'Neill's 8/1 shot.
The dual Welsh National winner won by two and a quarter lengths from 50/1 outsider The Giant Bolster.
Defending champion and 7/4 favourite Long Run was three quarters of a length back in third after two-time former champion and crowd favourite Kauto Star was pulled up early by Ruby Walsh.
Midnight Chase made the early running as 13 took on the three-mile, two-and-a-half-furlong trip but that was soon 11 as What A Friend fell at the second before Kauto Star's bid to win a third Gold Cup at the age of 12 - after his previous triumphs in 2007 and 2009 - ended when Walsh pulled his mount over.
Six of the last nine Gold Cup favourites have triumphed and Nicky Henderson's eight-year-old Long Run look poised going over the last but Synchronised, owned by JP McManus, powered away up the hill with The Giant Bolster also overtaking Sam Waley-Cohen's mount.
McCoy, whose previous Gold Cup victory came on Mr Mulligan in 1997, said: "It's great for Jonjo and JP McManus. He's really delivered today.
"He was off the bridle the whole way and when I missed the third-last I thought my chance had gone."
It was a first Gold Cup triumph as a trainer for O'Neill, who memorably rode Dawn Run to victory in the race in 1986.
"Magic, this is a big team effort...everybody had done so much work on this horse," O'Neill commented.
Kauto Star, whose participation in the Gold Cup was in jeopardy following a schooling fall a fortnight ago, returned from the race unscathed.
Trainer Paul Nicholls said: "He's absolutely fine. Ruby wasn't happy after he'd jumped a couple of fences and we said if he wasn't happy to pull him up, and he's done the right thing. There's obviously something tweaking him."
Countrywide Flame caused a real shock in the opening race of the final day at the Festival by landing the Triumph Hurdle at 33/1.
A wide open renewal saw three promising young hurdlers go over the last in a line but Dougie Costello's mount powered away up the hill to win by three lengths.
Hisaabaat (20/1) followed the winner home with 5/1 favourite Grumeti a further three quarters of a length back in third.
After Cape Tribulation gave Malcolm Jefferson victory on Thursday, John Quinn saddled another winner for the North.
Quinn said: "He's never run a bad race yet but I did think he had to find plenty to win. He's won three races, been second in a Listed race, and was third in a Grade One in Ireland and second in a Grade One at Chepstow.
"He's very tough and hardy and stuck at it really well. He's not very big, and got buffeted about, but I'm really pleased."
Alderwood landed the Vincent O'Brien County Handicap Hurdle with McCoy getting his first win of the Festival.
McCoy negotiated some heavy traffic in the 26-runner field to hit the front going over the last and taking victory by three quarters of a length from Edgardo Sol (25/1).
Sailors Warn (16/1) and Plan A (20/1) completed the places as Ireland won the race for the 14th time.
"He's not very big, but he's tough," said the winning jockey. "Horses like this are brilliant."
"I was getting knocked about going to two out and I thought I would just try and find some room going to the last.
"He pricked his lugs and flew the last. It's great for all the lads in the yard."
Brindisi Breeze held on to win the Albert Bartlett and foil a big gamble on Boston Bob.
A roaring finish from Lucinda Russell's gelding, who was always at the sharp end of the pace throughout the three-mile trip, saw a triumph by two lengths from the 6/5 favourite.
The 25/1 chance Grand Vision was a length and a quarter back in third with the winning Scottish raider steered home by Campbell Gillies.
Six of the seven winners of this race have started at less than 10/1 and the winner came in at 7/1.
Russell said: "It's just fantastic as his owner, Sandy Seymour, only has one horse. It's what you work for. You spend all winter trying to put them in the right races and it's just amazing that the right race happens to be at Cheltenham.
"He's very tough - he doesn't like horses passing him. He's not the fastest in the world - he doesn't burn up the gallops - but he's so brave and he jumps quickly. He'll be a fantastic chaser and that's what he'll be doing next season."
Salsify held off the heavily backed favourite Chapoturgeon to win the Foxhunter Chase.
The promising Irish hunter-chaser, under Colman Sweeney, landed the race for amateur jockeys by a length from the 3/1 jolly.
Oscar Delta (28/1) was 11 lengths back in third.
Attaglance got up in the final furlong to win a thrilling Martin Pipe Conditional Jockeys' Handicap Hurdle.
After a 17 year wait for a winner at the Festival, Malcolm Jefferson saddled his second in as many days.
Toner D'Oudairies led going over the last but made a mistake and was edged out by a neck by the 20/1 chance, rode by Harry Haynes.
Oscar Nominee (10-1) was a neck back in third ahead of Make A Track (12-1).
I weighed into Tanks For That in last year's renewal and tore up my betting slip after two fences as he charged out like a bat out of hell and failed to settle. He looks a different horse this year and has the class to be up with the pace before charging clear up the hill. Stable jockey Barry Geraghty has plumped for this one for in-form Nicky Henderson who always targets this race named in honour of his father.