Patrick Mullins had not scored in more than a year, a promising season having been derailed by injuries and poor form. But on Saturday night, the former University of Maryland star not only smashed his way out of a funk, he set an MLS record.

Mullins became the 11th player in league history to record four goals, and he did it in the shortest span in MLS’s 22 seasons — a 31-minute masterpiece during D.C. United’s 4-0 victory over the San Jose Earthquakes before a season-high 25,229 at RFK Stadium.

All of them came in the second half – on a redirection, on a header, on a rebound and on a free kick.

Two United players had accomplished the feat (Raul Diaz Arce twice and Abdul Thompson Conteh), but neither did it in such a startling manner. Mullins had gone scoreless in his first 15 appearances (including eight starts), leaving the organization to wonder whether he would have a firm place on the squad next year.

“It was a long road for me — maybe longer than I expected to be back at full sharpness,” said Mullins, who in less than one half became United’s second-leading scorer this year and fell one goal short of the MLS individual record, set by Clint Mathis in 2000.

“As a striker, you want to score goals,” defender Kofi Opare said. “And when you don’t, thinking about it takes a toll. It took a burden off his shoulders. We all know Patrick is a class forward, and it just took that one goal to get his confidence going. He scores four goals, and he scores a free kick, which I’ve never seen him do. When you’re confident, you can do anything.”

No one in the league had scored four times since Jeff Cunningham for FC Dallas in 2009.

“It’s a long time coming for Patrick,” Coach Ben Olsen said. “It’s hard to score four goals — it’s a lot of goals. But it’s been a long time coming for the group.”

United (9-17-4) had pocketed more than two goals just two other times this year and never at home. United hadn’t scored multiple goals at RFK in three months.

The outcome dented the playoff hopes of the Earthquakes (11-13-6), who are stuck in a tight race in the Western Conference. United was in control almost the entire night, yielding only a few genuine chances.

In the twilight of a disappointing season, with the playoffs out of reach and attention pivoting to 2018, Olsen is taking a hard look at players who may fill key roles.

On this night, the focus was on Mullins and goalkeeper Steve Clark, the prime candidate to start next year if Bill Hamid does not sign a new contract. Clark made his first appearance since joining United last month from a Danish club, and he was barely tested.

Per usual, United failed to capitalize on early opportunities. The best chance of the first half came in the 23rd minute, when Russell Canouse’s 12-yard header hit the right post and Paul Arriola snapped the rebound over the crossbar.

There were no such issues in the second half. Arriola set up Mullins’s first two goals, on a low cross in the 57th minute and on a high cross in the 60th.

Eight minutes later, Andrew Tarbell made a terrific save on Zoltan Stieber’s wicked free kick from 35 yards. The rebound fell to Mullins for his second career hat trick.

Then, in the 88th minute, he drove a 19-yard free kick around the defensive wall and into the far corner.

“I think this was coming for me – maybe not this type of performance,” Mullins said. “It has been challenging [this year]. Personally, it was gratifying, this performance.”

Notes: D.C. will visit the New York Red Bulls on Wednesday and Columbus Crew on Saturday. … The previous home attendance high this year was 20,618 against Chicago in May.