The Spaniards fought back in the final quarter, but strong second and third periods proved decisive for the Montenegro, who hung on for victory.
Montenegro will now hope to improve on Beijing 2008, where they lost a semi-final to eventual winners Hungary, only to lose again to rivals Serbia and come in fourth place, missing out on a medal.
The 2012 European Championships silver medallists scored first in the opening minute of the game, but Spain equalised soon after. They were level at the end of the period with four goals apiece before a dominant second quarter saw Montenegro forge a two-goal lead.
They went ahead through a well-worked man-up goal which was flicked in from close range.
Montenegro missed a great chance to grab another, but they failed to take advantage of a counter-attack by striking the crossbar.
Instead, Spain were able to equalise through a power-play.
Montenegro were fortunate to go ahead once more after the Spanish goalkeeper allowed a soft man-up shot to squeeze past him, and they added to their total with another power-play to take a 7-5 lead.
Spain did have their chances, but an impressive defensive display from the Montenegrins stopped them from capitalising on extra-player advantages.
The eventual winners extended their lead to three in the opening minutes of the third quarter.
Spain pegged one back from a man-up goal, but Montenegro netted two more man-ups to take a four-goal lead into the final period.
Three unanswered goals from Spain brought them to within one goal of Montenegro in a tense fourth quarter. However, Montenegro settled their nerves with around 90 seconds left by firing in a power-play.