Wales led 16-10 in the final quarter but a try from Francois Hougaard put the Springboks back in control.
Fly-half Rhys Priestland missed a drop goal in front of the posts and James Hook sent a more difficult penalty attempt wide.
Gatland said: "I'm proud of the effort the players put in but we didn't win the game.
"We put ourselves in with a chance to win but I think we weren't quite good enough.
"The players will be devastated but we had a chance - a drop goal in front of the posts, Hooky had a penalty.
"It's all about competing at the highest level and that's just the little half a percent we've got to learn from."
"We're bitterly disappointed," James Hook added on ITV1.
"We came so close. We were quite confident all week but we came up just short."
He added: "We played really well and we didn't quite get the victory and in a tournament like this, it's all about getting the win."
Hook contributed 11 points with his boot but the eye-catching Welsh performance came from Toby Faletau who scored their only try.
"Toby's a fantastic player - he's only 20 years old but he's just getting better and better," Hook said.
Gilbert has released a new line of rugby cleats. The Gilbert Virtuo 8S is part of the exciting new product. Check it out.
The entire All Blacks apparel line has been updated for 2013/14. Check out the New Zealand All Blacks polo.
The Nike Tiempo is a solid rugby cleat and one of few styles still made from full-grain natural leather.
The Gilbert Blitz 8S rugby cleat is a great cleat at a great price of $69.99. Get a new pair of cleats today.
A cool looking all black rugby cleat with the high performance adidas is known for. Get in the Gear!
Wear the crest of the British and Irish Lions on your t-shirt. A great look for the summer.
The All Blacks Performance t-shirt is black with hints of blue from the training jersey. Very Cool.
The New Zealand All Blacks training jersey for 2013/14. Get in the Gear!
The USA Rugby Pro Alternate rugby jersey is perfect for any fan of the Eagles. Get yours to wear during the summer Test matches.
The NEW All Blacks 2013/14 jersey has arrived at World Rugby Shop. Dare to wear the colors of the All Blacks.