No. 40 Squadron was formed at Townsville, Queensland on 31 March 1944. It was initially equipped with six Short Sunderland flying boats which had been ferried from the United Kingdom to Australia between January and March of that year. These ferry flights were made by experienced crews drawn from the RAAF's two Sunderland squadrons in the United Kingdom, No. 10 and No. 461 squadrons. The squadron's main role was to fly regular transport services between Australia and New Guinea. The Sunderlands were modified to operate as transport aircraft, and the first aircraft to be fully converted was delivered to No. 40 Squadron on 1 July. Most of the squadron's pilots were veterans of operations in the Battle of the Atlantic with No. 10 and No. 461 squadrons. On 22 Julythe unit moved to Port Moresby in New Guinea, with detachments at Darwin and Townsville. No. 40 Squadron's main destinations were Cairns, Milne Bay, Madang and Townsville. A No. 40 Squadron Sunderland was involved in the first attempted hijacking of an RAAF aircraft on 14 September 1944. The aircraft had been tasked with flying prisoners, including US Military prisoners, from Cooktown to Port Moresby. One of the American prisoners being transported to the aircraft on board a launch seized a gun from one of his guards then disarmed the other guards. When the boat reached the Sunderland he tried to persuade the prisoners embarked on the plane to assist him, but they were unwilling. The boat then preceded to a jetty in Cooktown Harbour where the man was persuaded to surrender. No. 40 Squadron suffered its only loss on 28 November when a Sunderland struck a post and sank after landing at Townsville; there were no fatalities. The squadron occasionally performed other tasks in addition to its regular transport fights. On 9 March 1945 one of its Sunderlands landed on a small lake in an isolated area of New Guinea to relieve an Army garrison force. No. 40 Squadron also undertook air sea rescue duties on several occasions. On 20 March 1945 a Sunderland located the survivors of a crashed C-47 and dropped them a dinghy. The Sunderland rediscovered the survivors the next day after contact was lost with them overnight, and maintained position over the dinghy until Allied naval vessels reached it. No. 40 Squadron's regular routes were altered in 1945. The service from Townsville to Port Moresby ended on 17 February and a new service between Port Moresby, Darwin, Karumba and Cains was established. A daily service from Port Moresby to Cairns began the next day and bi-weekly flights to the Treasury Islands commenced on 26 February. In July the squadron was issued with four Martin Mariner flying boats which were based at Cairns and also operated in the transport role. Following the Japanese surrender the squadron flew ex-prisoners of war and other soldiers back to Australia. It was allocated Catalina aircraft in January 1946, but none were ever delivered. No. 40 Squadron moved to RAAF Base Rathmines on 6 March and was disbanded there on 19 June. By this time it had flown 1782 sorties and carried of cargo and 43,385 passengers.