As foreign troops invaded Beijing during the Second Opium War and the Xianfeng emperor fled to Chengde, Wenxiang remained in the capital and took part in negotiating with the British and French.