The finer details of the Code will now be finalised by all parties by the end of August.
The Code means that in future, contracts between farmers and dairy processors will be freely negotiated, fairer and more transparent.
Individual farmers will negotiate contracts covering issues including pricing, notice periods and farmers will have the ability to leave contracts more easily if they are unhappy with the price they receive.
Speaking at the Royal Welsh Show where the agreement was reached, Farming Minister Jim Paice said:
“I welcome the commitment all sides have shown to reaching an agreement.
“The Government will continue to work with all parts of the industry to secure its long-term future, including promoting farmers working together in Producer Organisations.”
On Wednesday, Defra Ministers will be meeting retailers individually to talk about increasing dairy industry sustainability through greater sourcing and promotion of British dairy products.