The man, known as Ruben, had been sleeping outside the stadium. Juan Manuel Serrano Arce/Getty Images

Real Sociedad have given a homeless man who had been sleeping outside a gate at their Anoeta stadium in San Sebastian work on their maintenance team.

The man, known as Ruben, had been sleeping there for the last eight months with his dog Mundo.

Ruben -- who had lived on the streets of San Sebastian for the past three years, surviving thanks to locals who brought him food and clothing -- has signed a two-month deal with the club.

Ya no tendrá que dormir en la calle, trabajará para la @RealSociedad https://t.co/e87L4UiYd9 pic.twitter.com/prVjdHPxb8 - MARCA (@marca) October 26, 2016

The 35-year-old will extend that contract if the work goes well, Spanish newspaper Marca reported.

Ruben, who has now found temporary accommodation, said: "I was starting to believe there were no good people. After so many blows, you lose hope."

La Real are seventh in La Liga after taking 13 points from their first nine league games.