This is despite the All Wales Medicines Strategy Group (AWMSG) advising the Welsh Government not to fund Prep on cost-effectiveness grounds.
Health Secretary Vaughan Gething has announced that during the research period "those for whom the drug is clinically appropriate can access it".
The trial will begin this summer.
An independent HIV expert group had already called the drug, which has got the go-ahead in Scotland, "highly effective" when used with the right groups and in the right doses.
AWMSG had said there were "several uncertainties and limitations" in the economic model provided by the drug company.
The Terrence Higgins Trust in Wales had called the AWMSG recommendation earlier this week "short-sighted," saying Prep could save the NHS money in the long term.
Mr Gething said there was no doubt that Prep - or Truvada - reduced rates of HIV infection when taken correctly and supported by wider, preventative sexual health services.
"The study will help us to learn how best to provide the preventative treatment to reduce risks of HIV transmission in Wales and answer some of the questions raised by the AWMSG around incidence rates," he said.
"The AWMSG is a highly regarded, independent expert group. I acknowledge their advice that there are uncertainties regarding cost-effectiveness and that they have not recommended the drug for routine use within NHS Wales at this time."
Around 150 new people are diagnosed with HIV in Wales each year, nearly half from sexually transmitted infection between men.
A daily dose of the pill is suggested for people at high risk who might not have safe sex. One estimate is it might cost Â£2.5m a year in Wales.
It is currently used in the US, Canada, Australia and France, and taken daily, it has been shown to reduce the risk of infection by 86%.
Stonewall Cymru, the lesbian, gay, bisexual and trans equality charity, has been campaigning for Prep to be made available on the NHS.
The charity's Wales director, Andrew White said: "This trial will allow Wales to protect those most at risk and given that it costs much more to treat than to prevent HIV, in the long-term this will also save NHS Wales money".
"Of course, Prep is not the sole answer to tackling HIV transmission. This preventative measure should be accompanied by high-quality sex and relationships education," he added.
Stonewall Cymru said it will now press the Welsh Government to make the drug available in the longer term.
It is not the first time a Welsh health minister has gone against advice over the cost of a drug.
Four years ago, then Health Minister Mark Drakeford approved the use of cystic fibrosis drug Kalydeco which was estimated at costing NHS Wales up to Â£180,000 per patient per year.
Neath AM Jeremy Miles, patron of LGBT Labour Wales, said: "We must take all appropriate action against preventable HIV transmission and the Welsh Government is listening to clinical experts who know the positive impact Prep could have alongside other measures to encourage safer sex."
A "game-changing" drug which dramatically cuts the chances of HIV infection will be provided in Wales as part of a three year trial.