A device for separating methane from a gas mixture containing oxygen, methane, carbon dioxide and hydrogen sulfide, comprising a gas compressor; a feed line for feeding said gas mixture to said gas compressor; a first membrane separation stage downstream of said gas compressor, comprising a gas separation membrane having higher permeability for carbon dioxide than for methane, providing a first retentate and a first permeate; a second membrane separation stage, connected to said first membrane separation stage to receive the first retentate as feed, said second membrane separation stage comprising a gas separation membrane having higher permeability for carbon dioxide than for methane, providing a second retentate as a product gas enriched in methane and a second permeate enriched in oxygen compared to the original gas mixture; optionally a third membrane separation stage, connected to said first membrane separation stage to receive the first permeate as feed, said third membrane separation stage comprising a gas separation membrane having higher permeability for carbon dioxide than for methane, providing a third retentate enriched in oxygen compared to the original gas mixture and a third permeate; a recycle conduit connected to a recycle feed point on said feed line upstream of said gas compressor, said recycle conduit being connected to said second membrane separation stage to receive said second permeate or, provided that the optional third membrane separation stage is present, connected to said third membrane separation stage to receive said third retentate or to both said second membrane separation stage and said third membrane separation stage to receive said second permeate and said third retentate, and at least one hydrogen sulfide adsorber comprising a bed of activated carbon having catalytic activity for oxidizing hydrogen sulfide with oxygen, said hydrogen sulfide adsorber being arranged between said recycle feed point and said first membrane separation stage. a gas compressor; a feed line for feeding said gas mixture to said gas compressor; a first membrane separation stage downstream of said gas compressor, comprising a gas separation membrane having higher permeability for carbon dioxide than for methane, providing a first retentate and a first permeate; a second membrane separation stage, connected to said first membrane separation stage to receive the first retentate as feed, said second membrane separation stage comprising a gas separation membrane having higher permeability for carbon dioxide than for methane, providing a second retentate as a product gas enriched in methane and a second permeate enriched in oxygen compared to the original gas mixture; optionally a third membrane separation stage, connected to said first membrane separation stage to receive the first permeate as feed, said third membrane separation stage comprising a gas separation membrane having higher permeability for carbon dioxide than for methane, providing a third retentate enriched in oxygen compared to the original gas mixture and a third permeate; a recycle conduit connected to a recycle feed point on said feed line upstream of said gas compressor, said recycle conduit being connected to said second membrane separation stage to receive said second permeate or, provided that the optional third membrane separation stage is present, connected to said third membrane separation stage to receive said third retentate or to both said second membrane separation stage and said third membrane separation stage to receive said second permeate and said third retentate, and at least one hydrogen sulfide adsorber comprising a bed of activated carbon having catalytic activity for oxidizing hydrogen sulfide with oxygen, said hydrogen sulfide adsorber being arranged between said recycle feed point and said first membrane separation stage.