The Welsh government has approved a £15.8m project to convert part of Cardiff Royal infirmary into a one-stop shop for health and social care services.

The first phase of redevelopment of the hospital, which had been threatened with closure, includes two GP practices, a pharmacy, and additional therapies and outpatient, mental health and substance misuse services.

The project also includes a major upgrade for Cardiff's sexual health service, the largest integrated sexual health service in Wales providing care to about 50,000 people each year.

Under the plans, sexual health services will be provided in a purpose-built department on one site.

Built in 1884, the hospital has grade II-listed status but at the end of the 20th century its future looked in doubt after it ceased to operate as a district general hospital and its casualty unit moved to the University hospital of Wales, Cardiff.

Plans to shut the infirmary's remaining facilities were successfully fought by campaigners in 2002, and in 2009 the Welsh government agreed to make sure the infirmary was used as a base for community health services.

Confirming the funding during a visit to the city centre hospital, health minister Lesley Griffiths said: "The whole scheme is in keeping with the aims of the Welsh government's vision for the NHS in Wales, Together for Health, which is based around community services with patients at the centre, and places prevention, quality and transparency at the heart of healthcare."

David Francis, chair of Cardiff and Vale university health board, said: "We are delighted with the announcement, which is a major step forward in helping us deliver on our commitment to provide services more locally whenever possible and appropriate."