Hidalgo, 26, missed a short birdie putt on the 18th hole to send fellow Spaniard Rahm into a playoff, giving the two-time major champion a chance to become the first player to win four Spanish Open titles.
Rahm birdied the final two holes of the round at Madrid's Campo Villa Club.
“Crazy, absolutely crazy,” Hidalgo said after Sunday's win. “It was weird because I was relaxed all day, even though I missed the short putt on the 72nd hole.”
After Hidalgo missed his putt, the players returned to the 18th hole for the first extra hole. Rahm drove over the green, chipped in close, and made the birdie putt. Hidalgo didn't miss his brief birdie attempt this time.
Back on No. 18, Hidalgo just missed the green and Rahm went left. Rahm chipped poorly and went over the green, and Hidalgo came close again and ran out of putts for his first win.
Hidalgo, who had never finished in the top three in 79 previous DP World Tour events, entered the final round with a two-stroke lead over Rahm. Hidalgo, who had three bogeys in his first six holes, shot a 1-under 70 for a total of 14-under 270.
Rahm, the former world No. 1, finished with a 3-under 68 and seven birdies, including three of the last five holes. He also had two bogeys and a double bogey.
Rahm was five shots behind heading into Saturday. He arrived in the Spanish capital late, after the birth of his third child.
Rahm won the LIV individual title and returned to Europe to try to qualify for the minimum four DP World Tour events required to compete in next year's Ryder Cup. He was allowed to compete after appealing the DP World Tour's sanction against him for competing on the LIV Tour.
Tommy Fleetwood shot a 5-under 66, his best round of the week, and finished tied for third.
Patrick Reed shot an even-par 71 and had two double bogeys to finish tied for 10th. Tyrrell Hatton shot a 3-under 68 to finish 10th. Shane Lowry shot a 2-under 69 and had a double bogey to tie for 13th.
Australia's David Micheluzzi also shot 71 to finish the weekend at 2 under and tied for 39th. Countryman Jason Scrivener also shot 71 and tied for 57th.
© Golf Australia. all rights reserved.