HMAS Castlemaine was commissioned at Melbourne on 17 June 1942 under the command of LCDR Philip J. Sullivan RANR (S). After commissioning Castlemaine proceeded to Sydney for completion and working up exercises, the latter comprising three days in Broken Bay, and escorting convoys from Sydney to Melbourne until she sustained damage in a collision with a Manly ferry in Sydney Harbour on the night of 11 August 1942. Repairs resulting from the collision were completed by Cockatoo Dockyard in seven days and the vessel proceeded to Townsville on 26 August 1942.
Castlemaine was engaged in escorting vessels from Townsville to Port Moresby for a few weeks after which she sailed for Darwin, arriving there on 5 October 1942. Almost immediately Castlemaine began her involvement in the hazardous task of supporting the Australian and Allied troops engaged in guerrilla operations against the Japanese occupation forces in Timor. Her first arrival in Timor was at Betano on 7 October 1942.
On 30 November 1942 Castlemaine and HMAS Armidale (I), whilst engaged in escort duties between Darwin to Betano, were subjected to three air attacks, but fortunately suffered no damage or casualties.
Late in 1942 Castlemaine was also engaged in escort duties between Darwin and Thursday Island. On 15 December, while escorting the merchant ships Period and James Cook from Thursday Island to Darwin, a Japanese aircraft scored a direct hit on Period, causing casualties (four fatal). Twice more that day and once the next day the ships came under air attack. These attacks were repulsed by Castlemaine’s anti-aircraft fire and the convoy reached Darwin without further damage or casualties.
After the force in Timor was withdrawn early in 1943, Castlemaine continued to operate in northern Australian waters on escort and general duties until December 1943, her duties including some minesweeping work. In December she was transferred to escort duties between North Queensland and New Guinea ports and remained on these duties until mid 1944.
During this period, on 18 December 1943, Castlemaine was making independent passage to Cairns when, at around midnight, she was diverted to render assistance to convoy TN 192. Seven of the eight merchant vessels in the convoy, along with one of the escorts, HMAS Gladstone (I), had run aground on Bougainville Reef on the Great Barrier Reef. By the time Castlemaine arrived at dawn on 19 December, Gladstone had managed to refloat herself and was waiting for daybreak in company with the other convoy escorts, HMA Ships Gympie (I) and Stawell (I), just clear of the reef. The vessels Colorado, Ambrose Bierce and City of Fortworth had also all managed to free themselves and, with Castlemaine and HMAS Lithgow arriving to assist, and her own starboard propeller damaged, Gladstone detached at just after 7.00am to escort the trio back to Cairns. Castlemaine assisted in disembarking troops and refloating the stricken vessels before proceeding back to Cairns that afternoon. She arrived at just after 7.00 that evening and subsequently returned to her own escort duties. All of the ships in the convoy were quickly refloated suffering varying degrees of damage.
From August 1944 Castlemaine was engaged in survey duties along the north coast of Australia. On completion of these duties she sailed for Morotai and the Philippines and thence to Hong Kong,
arriving there on 29 August 1945, where she took part in the Japanese surrender ceremony and later carried out minesweeping duties. After some further minesweeping and survey work in northern Australian waters Castlemaine returned to Melbourne in November 1945 where she paid off into Reserve on 14 December 1945. She was later immobilised at HMAS Cerberus, Crib Point, Victoria, as a training hulk for Engine Room Artificers.
In September 1973 the Minister for Defence announced that the Government had decided to make a gift of Castlemaine to the Maritime Trust of Australia, to become a maritime museum. She was transferred later in the year.