San Francisco housing officials said Friday they have reached an agreement to purchase the notorious McDonald’s at Haight and Stanyan streets, a fast-food outlet that for years has been better known for brawls and drug busts than its Big Macs.

While officials wouldn’t comment on terms of the deal — the final agreement has not been signed — real estate sources said the Mayor’s Office of Housing will pay about $10 million for the 38,000-square-foot parcel, which would become the site of an affordable housing complex. The property could accommodate about 90 housing units, although a developer could conceivably seek to construct more under the state affordable housing density bonus program.

“Anytime we can acquire land for affordable housing, we need to do it,” said Mayor Ed Lee. “Affordable housing — or the lack thereof — affects everyone in our city.”

A one-story building at the end of Haight Street with a 45-car parking lot, the McDonald’s has long been a source of complaints from neighboring residents and business owners. Between January 2014 and April 2015, there were 640 calls to police and 11 drug busts.

The situation was so bad that City Attorney Dennis Herrera issued a clean-up order in May 2015, calling the McDonald’s a public nuisance.

McDonald’s and its local operator settled with the city for $40,000, agreeing to add more security and better lighting. A new franchisee, Peter Ou, took over the location in January and has done a good job cleaning up the property, said San Francisco police Capt. John Stanford of Park Station. Ou installed a new security surveillance system and meets regularly with police, fellow merchants and staff from Supervisor London Breed’s office. A beat officer is regularly posted on the corner.

“With everybody working together, we have been able to reduce the crime at that location,” said Stanford, who was checking in on the property on Friday afternoon.

But problems have persisted. On Aug. 2, a 28-year-old man was shot there in the middle of the afternoon, suffering injuries that were not life-threatening.

Even if public safety has improved, city officials see the parcel as grossly underutilized and perfect for housing. Breed, who represents the area, said that she would like to see a project that includes both deeply affordable units and apartments designed for middle-income households.

“If we can pull this deal off and build affordable housing there, it would be amazing,” Breed said.

Kate Hartley, acting director of the Mayor’s Office Of Housing, said that the size and location make the McDonald’s site special. The last affordable housing development in the Haight neighborhood, a senior development across from Buena Vista Park at 1250 Haight St., opened in 2007.

“The neighborhood is fantastic. It’s across from the park. And it’s a really good size,” Hartley said. “It’s a treat to have an opportunity to buy a site of this size.”

The McDonald’s has frequently been associated with the largely homeless crew of teenagers and young adults who hang out in Golden Gate Park across from the restaurant. On Friday, several of the regulars sprawled on the grass there with their backpacks and dogs said that they no longer frequent the McDonald’s. They prefer the Whole Foods on the other side of Haight Street.

“I’m in support of putting housing, but getting rid of the McDonald’s is not going to stop the drug dealers,” said Mark Utter, who said he has been hanging out in the neighborhood for 30 years. “You could put a police station there and it’s not going to change Haight Street from doing what it’s always done.”

Tony Green, a manager at Amoeba Records next door, said some of his workers might miss the proximity to fast food, but residential units on the corner would be good for the neighborhood, he added.

“A lot of tourists go there, some of our employees go there, but it’s safe to say that everybody who works here would be totally comfortable with housing there,” he said.

J.K. Dineen is a San Francisco Chronicle staff writer. Email: jdineen@sfchronicle.com Twitter: @sfjkdineen