The American had slipped out of contention after opening with a bogey and then making eight straight pars, but he suddenly found another gear on the back nine.
Spaun fired his tee shot to three feet at the 14th before sinking birdie putts from 15 and 16 feet on the next two holes. A two-putt birdie at the 18th completed a 67 and left him at 17 under.
Elvira then produced an eagle at the 17th to join Spaun at the top of the leaderboard, but his challenge unravelled on the last.
The Spaniard found a fairway bunker from the tee, laid up into another bunker and sent his next shot over the green. His attempted recovery found sand again before he eventually signed for a double bogey and a 70.
Elvira finished two shots behind in a tie for second with Rory McIlroy, Adam Scott and Aaron Rai.
Spaun, the 2025 US Open champion, said his omission from the United States Presidents Cup team had provided extra motivation.
"I played with a huge chip on my shoulder," he said. "Being left off the Presidents Cup team was very disappointing. I wanted to prove that I deserve to be on the team."
Rai closed with a 66, while McIlroy and Scott both carded 68s. McIlroy's finish also helped him cut into Patrick Reed's lead in the Race to Dubai standings.
Spaun became only the third American to win the BMW PGA Championship after Arnold Palmer and Billy Horschel, and the first player to win on his debut since Byeong Hun An in 2015.
The victory was Spaun's second of the year after his Texas Open success and his fourth career title.
"I've kind of blossomed into this player I never thought I could be," he said.