Josh O’Brien learned at an early age the importance of patience and compassion when trying to help people in desperate circumstances.

And, as director of Portland’s largest homeless shelter for the past decade, he was known for his ability to see the humanity of the men who had nowhere else to go.

“My folks both worked in shelters since I was quite young, so I sort of grew up in the shelter environment,” O’Brien said. “After school, I would go to the shelters they were working at, volunteer and just run around, so it’s always been a comfortable environment for me.”

O’Brien will step down Thursday as the director of the city’s Oxford Street Shelter to become shelter director for the Pine Street Inn, a Boston nonprofit that has a men’s shelter with more than 300 beds and serves 1,600 homeless people a day in a city with more than 7,000 homeless residents. Pine Street Inn is the largest provider of services to the homeless in New England.

Portland’s Oxford Street Shelter, by comparison, has a maximum capacity of 154 people and Maine’s largest city had 497 homeless residents as of the last federal census in December.

“Josh leaves behind an impressive legacy here in Portland,” City Manager Mark Rees said in a written statement. “His compassion and commitment to ending homelessness make him very well-suited to lead that organization and they are lucky to get him.”

O’Brien will join Pine Street Inn July 21 and oversee the men’s shelter and related programs.

In Portland, O’Brien was one of a core group of people dealing with a dramatic increase in homelessness, particularly in the past few years. “Bed nights” at the adult shelter – total occupancy – increased 37 percent in the past eight years, from 81,260 in 2005 to 111,283 in 2013.

But officials believe the city is turning a corner, thanks largely to initiatives in which O’Brien played a key role. He served on the city’s task force to prevent and end homelessness.

Rather than providing a limited amount of services to many people, the shelter now works intensely with people who are considered chronically homeless. The city requires long-term homeless people to develop a housing plan and helps them achieve it by working with landlords to secure apartments, finding furniture and following up with people after they are housed.

The shelter also has redoubled its efforts to house homeless veterans, who account for nearly 10 percent of the people served by Oxford Street. In fiscal 2013, 86 veterans were placed in housing, and 199 veterans were served by the shelter.

“Certainly we’ve made a lot of progress in addressing issues related to homelessness and emergency shelter over the last couple years, and Josh has been right in the middle of it,” said Portland Mayor Michael Brennan.

O’Brien’s mother worked in a shelter for battered women, while his father helped establish a halfway house for adults and would go on to become the New England regional director of the U.S. Interagency Council on Homelessness in Boston.

O’Brien recalled going to a halfway house and watching as his father, John, related to his clients, not as addicts or vagrants, but as human beings.

“That’s what I try to do here every day,” O’Brien said. “We all have flaws and troubles in our lives. I remember those interactions and know that it could be any one of us.”

Jim Devine, a recovering alcoholic who is now an advocate for Portland’s Homeless Voices for Justice, a group of formerly homeless individuals, said O’Brien would attend the group’s monthly meetings and always kept open the lines of communication about issues ranging from policies to individual clients.

“I think he’s a caring individual who has done a wonderful job in a very difficult position,” Devine said. “He’s dealing with a crowded environment that has a lot of difficulties from time to time and I think he’s done well.”

The Oxford Street Shelter has enough capacity – with mats placed on the floor – to house 154 people, but a recent increase in the number of people with medical issues who must sleep on cots dropped that capacity to about 130 beds.

The number of people seeking shelter routinely exceeds that capacity. At times in 2012, more than 400 people a night sought shelter. That record was broken in 2013. An average of more than 500 people a night sought shelter last September.

That has forced the city to be creative to deal with the overflow. Temporary shelter has been provided at the Preble Street Resource Center and the city’s general assistance office.

O’Brien was able to find solutions to the overcrowding, while also navigating the constraints of a municipal bureaucracy and keeping his overworked staff motivated to do the same, said Mark Swann, executive director of Preble Street.

“It’s not just running one shelter anymore. It’s running an overflow and then another overflow and doing it with the dignity of the clients at the forefront and we’ve been really appreciative of that,” Swann said. “It’s really complicated stuff, and he’s pulled it off. … I think he’s been a real jewel in the city for a long time.”

In 2012, O’Brien received the city’s “Robert B. Ganley Public Service Award,” which was established in 2002 to honor public service and named after a former city manager. In a way, it was a fitting award, since it was Ganley who, in response to a homeless encampment at City Hall, declared in 1987 that the city would never turn away anyone seeking shelter.

“That speaks to the high esteem that people in city have for (O’Brien),” Brennan said. “He’s done a terrific job. He will he hard to replace.”

The 42-year-old O’Brien, who lives in York with his wife and two children, said he didn’t make the decision to leave lightly, since there are so many people here – from social service agencies, to city officials to community leaders – who are dedicated to ending homelessness.

Despite occasional tension, O’Brien credited the neighborhood around Oxford Street for its support.

“It’s pretty rare to have such a large shelter in such a densely populated area,” O’Brien said. “The warmth and understanding this neighborhood has had is pretty remarkable. I don’t think they get enough credit for that.”