The decision was confirmed just hours after a motion of no confidence was lodged in Mr FitzPatrick at the Scottish Parliament, with two opposition parties saying they wanted him to step down.
Mr FitzPatrick had faced persistent calls to resign after yearly figures released earlier this week showed a rise to a new record high of 1,264 drug deaths last year.
He confirmed he was quitting following a discussion with First Minister Nicola Sturgeon.
He has been replaced by Angela Constance, who has been appointed as the minister for drug policy dedicated to addressing the crisis.
Ms Constance, a former criminal justice social worker, will report directly to the First Minister
She will remain in the role until the Holyrood elections in May, with her appointment to be put to Parliament for approval next week.
Mr FitzPatrick said in a statement: “I spoke with the First Minster today and agreed that I should leave government.
“It has been the privilege of my life to serve in the Scottish Government and, during that time, the most heart-breaking and difficult problems I have faced as Public Health Minister is the harms and deaths caused by drug use.
“I have worked with families who have felt the burden and weight of grief from drug use. I want to thank them for their candour and the amazing efforts they make to try and make our country better and safer for all.
“As the minister responsible for this area I, ultimately, take my responsibility.
"It is clear that my presence as a minister will become a distraction, when we should be focused on achieving the change we need to save lives.
“There is nothing I can express that will ease the loss that so many families have felt due to a death from drugs use. I can only say how sorry I am for their loss, and that hearing the experiences of the families and the recovery communities will never leave me.”
The Scottish Government said a new minister for public health would be nominated on Monday.
Ms Constance said: “It is a privilege to be asked to work with the First Minister to address this challenge.
“I intend to get straight down to business, meeting with people who are at risk of dying from drugs, learning from the families of those we have lost and working with those in our communities and public health teams who are providing such valuable support.”
Scotland has the worst drug deaths rate in Europe.
Last year’s 1,264 deaths was double the number recorded in 2014, giving the country a death rate three-and-a-half times higher than England and Wales.
Ms Sturgeon said: “I thank Joe for his work as a minister and the service he has given to government over the last eight years, firstly as minister for parliamentary business and then as minister for public health.
“While the time has now come to make a change in the public health brief, no one should doubt Joe’s hard work, dedication and sincerity.
"He will continue to champion the interests of his constituents at Holyrood, and I wish him well in the future.”
Scottish Labour and the Liberal Democrats had earlier formally called for him to go.
Labour's Monica Lennon had earlier submitted a motion of no confidence in the minister on Friday, citing "his inadequate response to tackling drug-related deaths".
Reacting to the announcement of Mr FitzPatrick’s departure, she said: “It is right that Joe FitzPatrick has resigned.
“Having been neglected for too long, Scotland’s drug deaths emergency must now be given the full attention of the Scottish Government.
“Urgent funding is needed to boost access to treatment and residential rehab. The Scottish Government must get behind safe consumption facilities, like the voluntary service being run in Glasgow.”
Scottish Conservative leader Douglas Ross said: "After 13 years of failure, no-one can have any confidence in Nicola Sturgeon's disastrous drugs strategy and the resignation of her public health minister changes nothing.
“If this was about the shocking number of drug related deaths this year, he would have gone on the day the numbers were released.
"The families of the 1,264 people who lost their lives in the last year to drugs will take little comfort in his resignation.
“They are more interested in how we have reached this shameful position after more than 13 years of the SNP being in power, with Nicola Sturgeon in charge of health for much of that."
"We urged the First Minister to agree to our proposed £20 million funding for rehabilitation, but got no commitment. All the focus must be on the urgent public health crisis of Scotland's drugs deaths epidemic so we can finally start to reverse the tragic number of lives being lost from drugs."
Lib Dems' health spokesman Alex Cole-Hamilton said: "Joe FitzPatrick is a likeable public figure, but has shown repeatedly that he's just not up to the job.
"He has publicly floundered when questioned about the vaccine and the devastating drug death statistics.
"He simply does not command the confidence of our party."
On Thursday, Ms Sturgeon had described the drug death figures as "completely unacceptable" and admitted the Scottish Government needed to do more to tackle the issue.
She is due to report to MSPs again next month after she meets a Scottish Government taskforce that is considering a number of public health interventions.
At First Minister's Questions, she pledged to "work with" Mr FitzPatrick to improve the situation as opposition parties accused her government of cutting its funding for rehabilitation beds.
Mr FitzPatrick earlier this week said the problem surrounding drug deaths had been "decades in the making".
He said the high number of deaths "stem from a long-standing and complex set of challenges" and there "really is no shortcut to suddenly solve this".