The term "gunship" is used in several contexts, all sharing the general idea of a light craft armed with heavy guns.
In the Navy, the term originally appeared in the mid-19th century as a less-common synonym for gunboat.
During 1942 and 1943, the lack of a usable escort fighter for the USAAF in the European Theatre of Operations led to experiments in dramatically increasing the armament of a standard B-17F Flying Fortress, and later a B-24D Liberator to each have a total of some 14-16 Browning AN/M2 .50 cal machine guns as the YB-40 and XB-41 "heavy fighters" respectively, each meant to accompany regular heavy bomber formations over occupied Europe on strategic bomber raids for long-range escort duties. The YB-40 was sometimes described as a "gunship" and a small 25-aircraft batch of the B-17-derived "gunships" were built, with a dozen of these deployed to Europe, while the XB-41 remained a prototype only.
In the more modern, post-WW II fixed-wing aircraft category, a gunship is an aircraft having laterally-mounted heavy armaments (i.e. firing to the side) to attack ground or sea targets. Most often, a gunship attacks the target while circling over it, performing a constant pylon turn. This is in contrast to a standard attack aircraft equipped with forward-firing weapon, that flies at the target and then passes over it.