Former Wales internationals Ryan Giggs, John Hartson, Mark Hughes and Neville Southall were among those who attended the memorial match for former manager Speed.
The national football association said the game was staged "to celebrate the life and achievements of a great servant to Welsh football both as a player and manager."
Speed, found dead at his home in November, won the first of his 85 caps against Costa Rica in May 1990.
After taking over as Wales manager in December 2010, he revived the team's fortunes.
While spectators held aloft banners reading "Gary Speed: Legend," captain Craig Bellamy led out the late manager's two sons Ed and Tom from the tunnel before a minute's applause was staged.
"It was all very difficult for us tonight under the circumstances... this night was for one guy and it was important for all of us to show support and celebrate his life... but obviously we are all still grieving over the loss of him," Chris Coleman, who was seen hugging Speed's parents before the start of the match, told Sky Sports after his first game as Wales manager.
"We knew this game was coming but we weren't looking forward to it. We had to do it because it needed to be done for a top fella... it's the least he deserved. We all miss Speeds."
Striker Joel Campbell put Costa Rica ahead in the seventh minute following a sublime one-two with Bryan Ruiz.
Wales came close to equalising on at least three occasions in the second half but Steve Morrison hit the crossbar, Bellamy shot over the bar and Hal Robson-Kanu's effort was brilliantly blocked by goalkeeper Keylor Navas.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.