On February 23, Spain marks 40 years since a failed coup attempt triggered a cultural revolution within the military, leading to its forced modernization and social integration.
For many Spaniards, memories remain fresh of a cold February afternoon when Lieutenant-Colonel Antonio Tejero stormed parliament with around 200 Guardia Civil officers, pistol in hand.
The attempted coup was staged by an extremist faction within the military that wanted to halt the nation's shift towards democracy after decades of dictatorship under General Francisco Franco (1939-1975).
But the plan went awry due to the decisive response of king Juan Carlos I, triggering a new era in which the armed forces abandoned their interventionist role and embraced new responsibilities in global peacemaking and civilian protection.
"We moved from the concept of institutions that wielded power to institutions that provided a public service of security and defense," said Admiral Manuel Garat Carame, who has been a part of the armed forces since Franco's death in 1975.
But how did an army accustomed to serving in a dictatorship and enjoying political privileges manage that shift?
Initially, military leaders decided to promote those known for embracing more democratic ideals rather than carrying out widespread purges.
"What could be changed was changed," recalls Abel Hernandez, a journalist who covered the transition from dictatorship to democracy.
"It wasn't a complete break from the past" because that would have meant getting rid of "up to 90 percent of the military leaders".
The biggest driving force for change at an operational level and in military culture was Spain's 1982 entry into NATO which opened the door for multiple peace missions with the United Nations and European Union.
Another milestone was the end of obligatory military service in the 1990s and professionalization of the military, which was placed under civilian control.
In 2008, Spain appointed Carme Chacon as its first female defense minister, about 20 years after women were first allowed into the military.
Chacon ushered in "an important feminization at all levels within the army," says analyst Diego Crescente, although progress has been slow with women only accounting for 12.8 percent of military personnel today, official figures show.
The transformation has taken years also owing to huge pressure from the Basque separatist movement ETA, which murdered dozens of soldiers and officials during the transition.
"The army's biggest accomplishment was its enormous self-restraint," says Crescente, co-author of a recent article in the Revista de Occidente journal called "Army and Society".
Alongside its international commitments, the Spanish army has become more visible back home as well thanks to its involvement in civilian emergencies.
The largest to date has been Operation Balmis during the first wave of the coronavirus pandemic when a record 189,000 troops were deployed for 98 days to build field hospitals, disinfect public buildings, and transport patients and medical equipment.
That boosted the military's image among Spaniards.
"Such circumstances make people's perception (of the army) much more positive," Garat told AFP.
"One of the things the army does very well, because it is hierarchical and functions at times of extreme tension, is respond to emergency situations," says Jaume Claret, a professor at the Open University of Catalonia.
But he said it was "questionable" whether the army should be systematically involved in civil protection duties.
As in other Western countries, several Spanish military figures have also made the leap into politics after retiring from active duty.
Some have gravitated towards the far-right Vox party, while others joined the Socialists of Prime Minister Pedro Sanchez, and in one case a former chief of staff joined the radical leftwing Podemos.
Last year, the military-political dimension hit the headlines after details were leaked from a Whatsapp group of retired officers who virulently criticized Spain's leftwing government and spoke of "shooting" 26 million Spaniards.
Although Defence Minister Margarita Robles denounced the authors as "not representing the armed forces at all", some analysts point to an underlying unease with Spain's minority government which has sought to improve relations with Basque and Catalan separatists.
"Not that there is going to be any more sabre-rattling but there is a lot of unease with the current government," Hernandez says.
"It is generating internal tension for military figures, as it is for many Spaniards, but more so" with the troops.