Both teams had already qualified with two wins from two, with today’s tie about who could finish Group B in top spot.
Spain got off to a good start, with Pablo Carreno Busta recovering from a set down against Jordan Thompson to win 2-6, 6-2, 7-6 (3) and clinch a 1-0 lead for the Spanish.
Montreal Masters champion Alexei Popyrin then levelled the tie with a straight-set win over Pedro Martinez Portero, beating the Spaniard 6-4, 6-4.
With the tie poised at 1-1, the result hinged on the deciding doubles match.
The Spanish again came through, with Pedro Martinez Portero teaming up with Marcel Granollers-Pujol to secure a 5-7, 6-4, 6-4 win over Australian duo Max Purcell and Matthew Ebden to secure the 2-1 win for Spain and top spot in Group B.