Ofgem is the UK regulator of the gas and electricity industries. Its main roles are to promote competition and to regulate the monopolies of the gas and electricity companies.
Because gas and electricity distribution are natural monopolies (it is highly unlikely that anyone will build duplicates of existing distribution systems) these require particularly tight regulation. For example, there are restrictions on the prices that can be charged for electricity transmission. Other markets (such as electricity generation) tend to be regulated with the aim of using competition to drive down prices.
Ofgem's duties go for beyond price regulation. The most important of its other responsibilities are to ensure the security of the UK's energy supplies (which implicitly includes the reliability of transmission networks) and to minimise disconnection of consumers through poverty.
More details are available on the Ofgem website