Right from the start, Juan Carlos defied expectations.

When 200 armed gendarmes stormed the Spanish parliament in 1981 it seemed the fledgling democracy, still finding its feet after 36 years of fascist dictatorship under General Francisco Franco, was doomed.

Spaniards, scarred from their bitter civil war and its repressive aftermath, disappeared from the streets and radio stations played sombre militaristic music.

But then something extraordinary happened. King Juan Carlos, crowned six years earlier when Franco died, appeared on television and ordered the troops back to barracks.

He demanded the loyalty of the armed forces, and, as the anxious country waited , they gave it. Spain's democracy was safe - and the King's popularity guaranteed.

A member of the royal Borbon line that stretches back to Louis XIV of France, the King's defusing of the attempted coup was all the more remarkable considering his background.

Juan Carlos was born in exile in Rome. His grandfather, King Alfonso XIII, was forced to leave Spain when the Republic was declared in 1931.

But after the fascist forces won the Spanish Civil War, the 10-year-old Juan Carlos went to school in Spain with the blessing of Franco. He went on to military colleges and developed a close relationship with the dictator.

So sure was Franco that his protege would continue his ultra-conservative style, he announced in 1969 that Juan Carlos would become king and head of state after Franco's death - bypassing the rightful heir, Don Juan (Juan Carlos' father).

Spaniards expected the King to maintain an authoritarian state. Instead Juan Carlos began modernising the economy and political system.

After the coup was thwarted, the pace of reforms picked up. It was an exciting time in Spain. Social and political movements that had been illegal or held back under Franco burst forth.

Communists, anarchists, hippies, punks, falangists, Basque and Catalan separatists exploded on to the streets.

In the space of a few short years, Spain ceased to be a conservative, God-fearing country and became one of the most liberal in Europe.

In the past 25 years, it has separated church and state, allowed abortion and divorce, and legalised gay marriage. A far cry from the Spain Juan Carlos inherited - a country where widows dressed in black, young women were chaperoned, sex was a dirty secret and the Catholic church was unassailable.

Now, though 80 per cent of Spaniards are Catholic, fewer than 30 per cent regularly attend church.

The King was right behind the changes. He was also instrumental in pushing Spain firmly into Europe. Until then, it had been considered a poor relation - Napoleon famously said that Africa "began in the Pyrenees".

Spain joined the European Union in 1986, and benefited hugely.

Massive injections of funding from the EU saw Spain upgrade its infrastructure, and its wealth and productivity grew exponentially.

Spain is now the world's eighth largest economy, and a major industrial power.

Juan Carlos' life has not been entirely charmed. When he was 18, his younger brother Alfonso died in a gun accident at the family's home.

The official line was that the Prince had died while cleaning a revolver, but rumours began to circulate that the gun had in fact been held by his brother Juan Carlos, though none suggested it was anything but an accident.

Married to the Greek-born Queen Sofia since 1962, Juan Carlos is widely seen in Spain as a "mujeriego" (womaniser). Most Spaniards have heard rumours about his mistresses, more than one of whom is supposed to have borne him children.

This does not seem to affect his popularity with the masses, and, in a country where romance and flirtation are widely celebrated, may even enhance it.

According to a poll by Spain's El Mundo newspaper in 2005, 78 per cent of Spaniards thought Juan Carlos was "good or very good". Other polls in Spain have given him similarly high approval ratings, and in 2008 he was considered the most popular leader in all of Ibero-America (the Spanish-speaking world).

His popularity went up a few notches further when he rounded on the Venezuelan President, Hugo Chavez, at the Ibero-American Summit in 2007.

Chavez was attacking the former Spanish prime minister, Jose Maria Aznar, when the King said "Why don't you shut up?"

Far from being seen as a breach of protocol, the King's anger was applauded - and the phrase was downloaded by thousands of Spaniards as a mobile phone ring tone.

Mostly the royals are spared the inspection the British media imposes on Buckingham Palace. But though offences against the honour of the royal family are protected by the Spanish Penal Code, the era of deference is closing.

Cartoonists from the newspaper El Jueves were tried and punished in 2007 when they published a caricature of Prince Felipe (heir to the throne) having sex with his wife, Princess Letizia. The row sparked small protests by Catalan nationalists, calls from at least one conservative commentator for the king's abdication, and prompted debate about the role of the monarchy and its privileges.

Queen Sofia got in hot water after a book, The Queen Up Close, gave Spaniards a revealing glimpse of her conservative views. Her thoughts on homosexuality, same-sex marriage, euthanasia and religious education outraged liberal Spaniards, and prompted an apology.

And her sports-minded husband - a 1972 Olympic skier - caused a stir of his own when he was accused of shooting a drunken tame bear during a visit to Russia in 2006. The royals and the Russians denied the story.

This is the second visit from the Spanish royals. The first was in 1988 and according to Spain's Ambassador to New Zealand, Marcos Gomez, the repeat visit is significant, given that we are as far away from Spain as it is possible to get.

"It's an indication of the importance of this region to Spain - we recognise that the Pacific is going to be the area of greatest dynamism in the 21st century, and we want to participate in that."

It's a high level visit: the touring party includes three Government Ministers, the Secretary of Commerce, and 22 top businesspeople.

Partnerships are on the agenda, with the idea that by helping Spanish companies into Asia Pacific markets, they could help New Zealand firms into the potentially huge Latin American market.

For that, we'll need Spanish - a language gaining ground in our schools and universities, with 30,000 students at secondary level and 2500 at universities. Spanish, spoken by almost 500 million people worldwide, is the world's second language.

The 71-year-old king will be busy on his four-day visit, opening the new Spanish Embassy and launching a working holiday scheme with Spain.

THE MAORI CONNECTION

High on the agenda of King Juan Carlos' visit is a meeting with a group of East Coast Maori who share a Spanish heritage.

The link stretches back to a whaler, Manuel Jose, who left Spain in the 1830s and joined the vessel Elizabeth in Peru. He reached New Zealand and became a trader.

East Coast records indicate he may have married up to five local women, who had eight children. The descendants number in their thousands and call themselves "Paniora", a Maori word for Spanish.

The family's Spanish roots have been traced to Valverde del Majano, north of Madrid. Two years ago a group from the East Coast went to Valverde for its annual fiesta. Diana Burns, who made a documentary for Spanish TV about the connections, said a "feeling of family" grew during the 10-day stay.

The king is to meet the Paniora in Wellington, nearly two centuries after a tall red-haired Spaniard left an indelible mark on this country.Diana Burns' documentary Beneath your Feet is on Maori TV at 8.30pm on Tuesday.