Andrew Griffiths said the joined-up nature of NHS Wales and a Â£11m computer investment meant fewer vulnerabilities.
His department coordinates computer systems across seven health boards.
Friday's cyber attack disrupted health organisations in England and Scotland.
But speaking exclusively to BBC Wales, Mr Griffiths, director of NHS Wales Informatics Service (NWIS) warned against complacency and said the organisation needed to be vigilant and to continue to invest in cyber-security in the face growing threats.
"We weren't lucky we were prepared and that preparedness stood us in good stead," he said.
"No system is 100% certain but we did have the systems processes and people in place to make sure the attacks couldn't get through.
"Because we had invested in infrastructure, because we've got a common infrastructure across Wales, we were able to patch more easily and keep up to date - because we were less fragmented it removed a lot of vulnerabilities from the system."
Mr Griffiths praised a superb effort from staff working around the clock to tackle the threat
"I'm immensely proud of on-call colleagues who came in. They called other colleagues - people who weren't on-call to come in.
"There wasn't a question about coming in... and everybody's worked superbly across the NHS. It was a brilliant exercise in cooperation."
But he warned against complacency and said lessons will be learnt
"Clearly we don't want cyber attacks, clearly we can't be complacent and we have to be vigilant and continue to make the right investments and continue to make sure our processes are working,
"There will be things too learn from this experience... But I think it's a good moment to recognise that planning and the fact we were prepared, that we've invested in common systems and processes have really paid off."
WHAT HAPPENED IN WALES?
The NHS in Wales was in stronger position to withstand the recent cyber-attack - not because of luck but because it was well prepared, the head of its computer operations has said.