Martin Zubimendi's volley from outside the penalty area meant Spain's first home game since winning Euro 2024 was a victorious outing against Denmark in the Uefa Nations League.
The European champions were heading for a frustrating draw until midfielder Zubimendi, who turned down the chance to join Liverpool in the summer, scored in the 79th minute.
Zubimendi beat Kasper Schmeichel with a first-time shot from about 22 yards which took a deflection before hitting the net, the Real Sociedad player's first goal for his country.
Schmeichel will feel he should have done better, but the Denmark goalkeeper had frustrated Spain until that moment with two fine saves to deny captain Alvaro Morata.
The Celtic keeper also kept out a decent attempt by 17-year-old Lamine Yamal before Zubimendi settled it in front of a sell-out crowd in Murcia.
There was a carnival atmosphere inside the ground before kick-off as Spain paraded the European Championship trophy they won by defeating England 2-1 in the final in Berlin on 14 July.
Saturday's victory meant Spain replaced Denmark at the top of Group A4.
Spain, who host Serbia on Tuesday, have seven points while Denmark, who go to Switzerland next, have six.