It was the 23-year-old first appearance at the Open de Espana and his third victory on the European Tour.
Dunne led by one shot overnight and a birdie on the 18th gave him a final-round 71 and outright second place.
Rahm and Elvira were both tied at 19 under on the 15th and a playoff beckoned, but Elvira hit the water with his first shot on the penultimate hole, leading to a double bogey.
"It's hard to describe the feeling of satisfaction and pride I have right now", Rahm said.
Facebook adds fuel to privacy row: We track non-users, says Zuckerberg
For the first time, Zuckerberg said that his data was swept up by an app that fed data on 87 million users to Cambridge Analytica .
"It's probably by far the hardest Sunday I've ever had to play just because of the amount of crowds I was carrying", he said.
He said 'I felt like I hit the ball great. I tried to isolate myself, but I could feel it. "I'm blessed to be national champion of the Spanish federation many times - European champion, world champion representing them - so to be able to do this as a pro and for them, and for the Spanish people, feels great".
Rahm began the day two shots behind Dunne after rounds of 67-68-66, but got off to a fast start on Sunday with back-to-back birdies on his opening two holes.
The tournament was eventually decided on the short 17th as Rahm escaped with a par after nearly sending his tee shot into the water, the ball just holding up in the rough.
The Greystones man appeared to be primed for one of the biggest victories of his career entering the fourth and final round however he failed to fire as he did on the previous days and ended up being overtaken by Rahm on the leaderboard.
Ed Sheeran in negotiations to star in Danny Boyle's untitled musical comedy
Ed Sheeran is rumoured to have been cast in a new musical comedy film directed Danny Boyle and written by Richard Curtis . A source close to Working Title, the studio that is making the film, said: " Everything Ed touches turns to gold ." .
Rahm birdied the last, although he didn't need it, to grab the trophy.
Ryder Cup stalwart Ian Poulter, who snatched a late place at the Masters Tournament following his play-off triumph at the Houston Open on the US PGA Tour earlier this month, was in contention for a second victory of the season at the RBC Heritage in SC as he approached the back nine just one shot off the lead.
The Spaniard, who's now the World number four, claimed a two-shot victory after carding a closing 67 to move 20 under for the tournament.
Will Dez Bryant let vendetta against Cowboys stop move to Ravens?
Last season, the 2010 first-round pick out of Oklahoma State finished with 69 receptions for 838 yards and six touchdowns. Bryant immediately deflected blame for Dallas' decision to release him , suggesting prominent players were behind it.