SARATOGA SPRINGS, N.Y. (AP) — Four weeks after becoming a Grade 1 winner with a last-to-first effort in the Met Mile at Belmont Park, Honor Code came up with an even more impressive encore performance Saturday at Saratoga Race Course.

Trailing by as many as 19 1/4 lengths, the 4-year-old son of A.P. Indy closed with a dramatic surge in the final sixteenth of a mile to catch Liam's Map and win the 88th running of the Grade 1 $1.25 million Whitney by a neck.

As a Breeders' Cup "Win and You're In" Challenge race, Honor Code earned an automatic berth to the $5 million Breeders' Cup Classic on Oct. 31 at Keeneland in Kentucky. He ran 1 1/8 miles in 1:47.82 and returned $9.50, $5.90 and $3.50 as the narrow second choice in a distinguished field of nine older horses.

"He's an amazing horse," said Hall of Fame trainer Shug McGaughey, who won his third Whitney and first since Personal Ensign in 1988 and Easy Goer in 1989. "To be able to win a race like the Whitney is a big feather in our cap."

Liam's Map led from the gate to the shadow of the wire and paid $7.40 and $4.50. Tonalist, the 2014 Belmont Stakes champion and 7-2 favorite, was 1 1/2 lengths back in third, returning $3.

"I could see Honor Code was coming, so I knew it would be really close until the finish," said Todd Pletcher, trainer of Liam's Map. "He just couldn't hold off a really good horse."

Breaking from the No. 1 post, the late-running Honor Code was unhurried early under jockey Javier Castellano as Liam's Map outran the speed-loving Moreno and took the field through testing early fractions of 22.79 for a quarter-mile, 46.00 for the half and 1:09.72 for six furlongs. Liam's Map opened up on the field in mid-stretch but Honor Code came with a relentless drive in the last 110 yards to get up in time.

"I kind of felt like I was going to have to work a little bit at the quarter pole, but he switched leads at the right time at the eighth pole," Castellano said. "He finished really strong."

One of seven Grade 1 winners in the field, Wicked Strong was fourth, followed by V.E. Day, Lea, Normandy Invasion, defending Whitney champion Moreno and Noble Bird.

On the undercard, Cavorting was an easy winner of the Grade 1 $500,000 Longines Test; Goldy Espony led from start to finish in the Grade 3 $200,000 Fasig-Tipton Waya; Under Control beat Charming Kitten by 1 1/4 lengths in the $100,000 Lure; and Recepta rallied to take the $100,000 Fasig-Tipton De La Rose.