Celta Vigo midfielder Mendez came off the bench in the second half and needed just 19 minutes to find the back of the net on Sunday, his strike coming after Ibrahim Sehic could only parry Isco's low drive.
Spain's margin of victory should have been wider but Alvaro Morata's toils for La Roja continued as he skewed wide prior to Mendez's winning goal.
Victory ensures Spain finish 2018 on a positive note after successive defeats in the Nations League, England's 2-1 win over Croatia earlier in the day ending Luis Enrique's side's hopes of reaching next year's Finals.
Spain's inexperienced side survived an early scare when Edin Visca broke through in the opening minute, but the forward was denied by Kepa Arrizabalaga.
It was a rare moment in the attacking third for Bosnia as Spain dominated possession, although they were unable to turn it into clear-cut chances.
Suso, Marco Asensio and Isco all blazed over before the latter finally brought a save out of Sehic five minutes before the break, the goalkeeper comfortably holding onto the Real Madrid midfielder's low shot.
Chances continued to be at a premium until the hour when Asensio fired low towards goal and the rebound should have been put into the unguarded net by Morata but he somehow managed to fire wide.
It was his final action as Rodrigo Moreno replaced him soon afterwards, but it was another substitute who settled the clash as Mendez did what Morata could not with 12 minutes to play.
What does it mean? Still work to do for Luis Enrique
Spain made nine changes, with eight of Luis Enrique's starting line-up holding less than 10 caps, and their inexperience showed at times in what proved to be a low-key affair.
Isco leads from the front
In a team lacking senior figures it was 26-year-old Isco who led from the front with a strong display in midfield, his surging runs bringing rare moments of quality for the hosts.
Morata's problems show no sign of ending
Morata's troubles in front of goal have been well documented and his failure to score on Sunday means he has gone over a year without finding the net for Spain.
With their Nations League campaigns over, both teams will turn their attention to the draw for the 2020 European Championship qualifiers in December.