EU energy ministers have agreed a plan to cap the price of gas, ending months of argument over how to handle the cost of soaring energy prices after Russia cut gas supplies to Europe.