According to early Chinese accounts, this northern coastal area was originally called Pak-kang (Chinese: 北港; Pe̍h-ōe-jī: Pak-káng). By the early 20th century, the city was known to the Western world as Kelung, as well as the variants Kiloung, Kilang and Keelung. In his 1903 general history of Taiwan, US Consul to Formosa (1898–1904) James W. Davidson related that "Kelung" was among the few well-known names, thus warranting no alternate Japanese romanization.
However, the Taiwanese people have long called the city Kelang (Chinese: 雞籠; Pe̍h-ōe-jī: Ke-lâng/Koe-lâng; literally: "rooster cage" or "hencoop"). It has been proposed that this name was derived from the local mountain that took the shape of a rooster cage. However, it is more probable that the name was derived from the first inhabitants of the region, as are the names of many other Taiwanese cities. In this case, the Ketagalan people were the first inhabitants, and early Han settlers probably approximated "Ketagalan" with Ke-lâng (Hokkien phonetics).
In 1875, during the late Qing era, a new official name was given (Chinese: 基隆; pinyin: Jīlóng; literally: "base prosperous"). In Mandarin, probably the working language of Chinese government at the time, both the old and new names were likely pronounced Kīlóng (hence "Keelung").
Under Japanese rule (1895–1945), the city was also known to the west by the Japanese romanization Kīrun (also written as Kirun or Kiirun).
In Standard Chinese, which became the official language of Taiwan after its handover to the Republic of China, the newer name is read Jīlóng (the shift from initial K to J is a recent development in the Beijing dialect, see Old Mandarin). However, the locals continue to call the city Ke-lâng across the changes in government.
Keelung was first inhabited by the Ketagalan, a tribe of Taiwanese aborigine. The Spanish expedition to Formosa in the early 17th century was its first contact with the West; by 1624 the Spanish had built San Salvador de Quelung, a fort in Keelung serving as an outpost of the Manila-based Spanish East Indies. The Spanish ruled it as a part of Spanish Formosa. From 1642 to 1661 and 1663–1668, Keelung was under Dutch control. The Dutch East India Company took over the Spanish Fort San Salvador at Santissima Trinidad. They reduced its size and renamed it Fort Noort-Hollant. The Dutch had three more minor fortifications in Keelung and also a little school and a preacher.
When Ming Dynasty loyalist Koxinga successfully attacked the Dutch in southern Taiwan (Siege of Fort Zeelandia), the crew of the Keelung forts fled to the Dutch trading post in Japan. The Dutch came back in 1663 and re-occupied and strengthened their earlier forts. However, trade with Qing China through Keelung was not what they hoped it would be and, in 1668, they left after getting harassed by aboriginals.
During the First Opium War between the British Empire and the Chinese Qing Empire, in the 1841 Battle of Keelung (1841-1842) the British attempted to attack in failed efforts three times against Keelung on the northeast coast of Taiwan under Qing rule. Attempts by the British to seize Da'an and Keelung by the British failed due to a successful defence led by the taotai Yao Ying who commanded the Chinese naval forces on Taiwan. Indian and European crew members of the Nerbudda, a British ship, were captured on Taiwan after being abandoned by their British officers and were executed by local Qing officials. Portuguese, Indian, American, and European crew members of the Ann, another British ship, were shipwrecked in the vicinity of Tamsui in March 1842, captured, and then executed by the Chinese. At Tainan, 197 of the Nerbudda and Ann's crews were killed and due to causes related to imprisonment 87 others died.
In 1863, the Qing Empire opened up Keelung as a trading port and the city enjoyed rapid development due to the abundant commodities such as placer gold and high quality coal found in the drainage area of Keelung River. In 1875, Taipeh Prefecture was created and included Keelung. In 1878, Keelung was formed into a ting or sub-prefecture. Around the same time, the name was changed from Ke-lang (雞籠廳) to Kilong (基隆廳), which means "rich and prosperous land".
During the Sino-French War (1884–85), the French attempted an invasion of Taiwan during the Keelung Campaign. Liu Mingchuan, who led the defence of Taiwan, recruited Aboriginals to serve alongside the Chinese soldiers in fighting against the French of Colonel Jacques Duchesne's Formosa Expeditionary Corps. The French were defeated at the Battle of Tamsui and the Qing forces pinned the French down at Keelung in an eight-month-long campaign before the French withdrew.
A systematic city development started during the Japanese Era, after the 1895 Treaty of Shimonoseki, which handed all Taiwan over to Japan. A five-phase construction of Keelung Harbor was initiated, and in by 1916 trade volume had exceeded even those of Tamsui and Kaohsiung Harbors to become one of the major commercial harbors of Taiwan.
Keelung was governed as Kīrun Town (基隆街), Kīrun District, Taihoku Prefecture in 1920 and was upgraded to a city in 1924. The Pacific War broke out in 1941, and Keelung became one of the first targets of Allied bombers and was nearly destroyed as a result.
After the withdrawal of the Japanese, Taiwan became part of the Republic of China (ROC) in October 1945, Keelung was established as a provincial city of Taiwan Province. The Keelung City Government worked with the harbor bureau to rebuild the city and the harbor and in 1984, the harbor became the 7th largest container harbor in the world.
Keelung City is located in the northern part of Taiwan Island. It occupies an area of 132.76 km2 and is separated from its neighboring county by mountains in the east, west and south. The northern part of the city faces the ocean and is a great deep water harbor since early times.
Keelung has a humid subtropical climate (Köppen Cfa) with a yearly rainfall average upwards of 3,700 millimetres (146 in). It has long been noted as one of the wettest and gloomiest cities in the world; the effect is related to the Kuroshio Current. Although it is one of the coolest cities of Taiwan, winters are still short and mild, whilst summers are long, relatively dry and hot, temperatures can peek above 26 °C during a warm winter day, while it can dip below 27 °C during a rainy summer day, much like the rest of northern Taiwan. However its location on northern mountain slopes means that due to orographic lift, rainfall is heavier during fall and winter, the latter during which a northeasterly flow prevails. During summer, southwesterly winds dominate and thus there is a slight rain shadow effect. Fog is most serious during winter and spring, when relative humidity levels are also highest.
Zhongzheng District is the seat of Keelung City which houses the Keelung City Government and Keelung City Council. The current Mayor of Keelung is Lin Yu-chang of the Democratic Progressive Party.
Keelung City voted one Democratic Progressive Party legislator to be in the Legislative Yuan during the 2016 Republic of China legislative election.
One of the most popular festivals in Taiwan is the Mid-Summer Ghost Festival. The Keelung Ghost Festival is among the oldest in Taiwan, dating back to 1851 after bitter clashes between rivaling clans, which claimed many lives before mediators stepped in. The Ghost Festival of Keelung City is a reflection of Taiwan's rich cultural history that is very much alive today.
Coal mining peaked in 1968. The city developed quickly and by 1984, the harbor was the 7th largest container harbor in the world.
Education in Keelung City is governed by the Department of Education of Keelung City Government.
Keelung City houses several universities and colleges, such as the National Taiwan Ocean University, Ching Kuo Institute of Management and Health and Chungyu Institute of Technology.
Keelung City houses the only fully oil-fired power plant in Taiwan, the Hsieh-ho Power Plant, which is located in Zhongshan District. The installed capacity of the power plant is 2,000 MW.
Bisha Fishing Port.
Chung Cheng Park, Heping Island Park.
Keelung Cultural Center.
National Museum of Marine Science and Technology.
Baimiweng Fort, Dawulun Fort, Gongzi Liao Fort, Keelung Fort Commander's Official Residence, Pengjia Lighthouse and Uhrshawan Battery.
The Taiwan Railways Administration stations of Badu Station, Baifu Station, Keelung Station, Nuannuan Station, Qidu Station and Sankeng Station cross Keelung City.
Taiwan's second largest port, the Port of Keelung, is located in the city. The port serves for destinations to Matsu Islands, Xiamen and Okinawa.