The Army of the Northern Headquarters (beifubing 北府兵) was an elite unit during the Eastern Jin period 東晉 (317-420). The aim for their creation was to defend the northern border against the Former Qin dynasty 前秦 (351-394), one of the Sixteen Barbarian States 五胡十六國 (300~430) that controlled north China. In 377, Counsellor-in-chief Xie An 謝安 (320-385) and his nephew Xie Xuan 謝玄 (343-388) suggested creating an elite body of troops. The latter was thereupon appointed General of Establishing Martiality (jianwu jiangjun 建武將軍) and regional inspector (cishi 刺史) of the province of Yanzhou 兗州 and chief commander of all troops north of the River Yangtze.
In the provinces of Yanzhou and Xuzhou 徐州, a substantial portion of the population consisted of refugees from the north (qiaomin 僑民, see refugee provinces) who were familiar with the topography and aspired to return to their homelands. This potential was recognised by Huan Wen 桓溫 (312-373), who proposed unsing these people as a reservoir of recruits. He found quite a few competent officers among them, like Liu Laozhi 劉牢之 (d. 402), He Qian 何謙, Zhuge Kan 諸葛侃, Gao Heng 高衡, Liu Gui 劉軌 (d. 404), Tian Luo 田洛, or Sun Wuzhong 孫無終. The seat of the high command was in Jingkou 京口 (today's Zhenjiang 鎮江, Jiangsu), a city called Beifu 北府, literally "northern quarter", during that time.
In 379, the new corps besieged the city of Pengcheng 彭城 (today's Xuzhou 徐州, Jiangsu), while the Former Qin armies advanced to the south and threatened the city of San'a 三阿 (near present-day Gaoyou 高郵, Jiangsu). Under the command of He Qian and Liu Laozhi, the two towns were liberated, and the Qin army thrown back. In the famous battle of River Fei 肥水 in 383, the Northern Headquarters Army defeated the Qin and reconquered many regions of what is today Henan and Shandong. Liu Niuzhi even advanced to the city of Yecheng 鄴城 (today's Linzhang 臨漳 near Hanhan 邯鄲, Hebei).
Command over the Northern Headquarters Army was soon given into the hands of Sima Yi 司馬怡, Prince of Qiao 譙. He rebelled in 397, but after his defeat, the command was given back to Liu Laozhi. Yet even Liu, who was critical towards the court, used the beifubing for his own purpose. At least, he supported the Jin court during the rebellion of Sun En 孫恩 (d. 402) in 399. In 402, he defended the dynasty against the uprising of Huan Xuan 桓玄 (369-404), before he decided to defect to the rebels. Huan Xuan swallowed the Northern Headquarters Army, barring a contingent, from which the commanders Liu Yu 劉裕 (363-422), Liu Yi 劉毅 (d. 412), and He Wuji 何無忌 (d. 410) built up a new force that eventually defeated Huan Xuan. Liu Yu in the end overthrew the Jin and founded the Liu-Song dynasty 劉宋 (420-479).