This process is known as electrorefining. It is one of the best methods known for producing metals of high purity.
In this process, the desired metal with impurities is takes as anode and a pure metal is taken as cathode. We also need to select an electrolyte with the same metallic ions.
When an electric current greater than the cell potential is passed, the metallic ions from the impure metal at the anode side are oxidized and pass into solution. And the metallic ions present in the electrolyte solution get reduced and get deposited on the cathode.