The FTSE 100 index closed up 17.73 points or 0.26% at 6,736.22.
Earlier on Monday, mining shares had been under pressure because of factors including disappointing trade data from China and falling metals prices.
But at the close of trading, they were among the biggest risers. Rio Tinto and Fresnillo led the list of gainers, both adding about 1.8%.
The sector bounced back despite a downbeat assessment from broking firm Investec, which lowered its forecast for commodity prices because of the weakness in China's economy.
However, supermarket shares failed to achieve the same turnaround. Tesco and Sainsbury's fell in early morning trading and stayed that way for the rest of the day, dropping by 1.4% and 1.2% respectively.
Shares in Dixons Carphone spent most of Monday in negative territory after the company said its Carphone Warehouse business had been hit by a cyber-attack, but closed with gains of 0.4%.
On Saturday, it said personal details of up to 2.4 million of its customers could have been accessed in the attack.
Engineering group Meggitt edged up 1% after it agreed to buy the advanced composites businesses from Cobham for $200m.
In the FTSE 250, shares in Esure dived 9.6% after the insurance group reported a 21% fall in underlying half-year pre-tax profits to Â£46.5m.
The main factor in the decrease was a big fall in profits at its motor insurance business, and the company said it would look to increase premiums.
Chief executive Stuart Vann said: "The claims environment in the motor market continues to deteriorate and as a consequence we will seek to implement further rate increases in the second half of the year as we look to mitigate against these trends."
On the currency markets, the pound rose 0.3% against the dollar to $1.5539, and was little moved against the euro at â‚¬1.4142.
(Close): UK shares turned positive late in the day as mining shares staged a recovery while supermarkets languished.