In a futures contract, the counterparty risk is primarily mitigated through the functions of the clearing corporation. The clearing corporation acts as an intermediary between the two parties involved in the futures contract. It ensures the performance of the contract by guaranteeing the obligations of both parties. This is achieved through processes such as daily marking to market, margin requirements, and enforcing rules and regulations. By providing central clearing services, the clearing corporation helps to reduce counterparty risk and ensures the smooth functioning of the futures market.