Ireland's Shane Lowry won the 96-man qualifying event after carding 11 under to finish two shots clear of Andrew Coltart and Montgomerie, who will extend his unbroken run of Open appearances to 21, dating back to 1990.
A total of 10 qualifying places were available to members of the European Tour who had not qualified automatically for the year's third major tournament.
Among those failing to qualify were former Ryder Cup players Darren Clarke, David Howell and Paul McGinley, while Italian teenager Matteo Manassero _ who at 16 in 2009 became the youngest winner of the Open's Amateur Silver Medal after finishing 13th at Turnberry _ also missed out.
Montgomerie described his morning round of 69 on the Old course as "not good enough" but made amends after lunch.
The Scot started his second round with birdies at his first two holes and finished with a birdie at the par-five 18th. He believed the last hole to be a par four and when he put his second shot into a bunker, thought a bogey might force him into a playoff.
But when he holed a four-foot putt for his eighth birdie in the round, he reached nine under and his place was safe.
"There was a moment of panic when the ball went into the sand but as it turned out, it's now a par five and I actually ended up with another birdie," Montgomerie said.
"But that was my best round of golf for a long time and it's very special to be going to St. Andrews again this year as the Ryder Cup captain. It's probably the last time I will play there in an Open in my career."
The 23-year-old Lowry, who won last year's Irish Open while an unpaid amateur, will play the first major of his career.
"At the start of the year, I said that I wanted to play this year's Open because it is always a great event at St. Andrews," Lowry said. "I have only played there once before as a professional _ in last year's Dunhill Links _ and didn't do too well, but the weather is very different in July than it was in October."
Manassero put himself in contention for one of the qualifying spots after a 6-under 64 over the Old course but followed up with a 71.
"The New course was playing a lot harder," Manassero said. "And I didn't play as well around there, tee to green. It is a big disappointment not to be going to St. Andrews."
Northern Ireland's Gareth Maybin and Thomas Bjorn of Denmark both shot 132 to qualify, while others to qualify were Jose Manuel Lara, Tano Goya, Ignacio Garrido and Bradley Dredge, who all carded 133.
Marcel Siem of Germany (134) won a six-man playoff to become the 10th and final qualifier.