We study the endogenous network formation of bilateral and multilateral trade agreements by means of hypergraphs and introduce the equilibrium concept of multilateral stability. We consider multi-country settings with a firm in each country that produces a homogeneous good and competes as a Cournot oligopolist in each market. Under endogenous tariffs, we find that the existence of a multilateral trade agreement is always necessary for the stability of the trading system and that the formation of preferential trade agreements is always necessary for achieving global free trade. We also find that global free trade is efficient but not necessarily the only multilaterally stable trade equilibrium when countries are symmetric (heterogeneous) in terms of market size. We derive conditions under which such a conflict between overall welfare efficiency and stability occurs.