The United States, who beat Honduras 1-0 earlier on Tuesday, lead the six-team group in the final round of qualifying from North, Central America and the Caribbean (CONCACAF) on 13 points from six games.
Costa Rica have 11 points from six matches while Mexico are in the third and final automatic place with eight points from six games.
The fourth-placed team, currently Honduras on seven points, meet Oceania winners New Zealand for a further place in the finals in Brazil.
In a rain-swept National Stadium in San Jose, Ruiz opened the scoring in the 47th minute from a free kick before Borges produced a long-range strike to double the advantage four minutes later.
Panama's Blas Perez returned from a stomach virus that had sidelined him but could not get the attack on track for the visitors.
- Sports & Recreation