Sean Franklin, left, and Davy Arnaud chase Jose Ortiz. (By Jeffrey Arguedas — EFE)

D.C. United had not played a competitive match in more than three months. Alajuelense was deep into its league campaign.

It showed.

The Costa Rican club toyed with the rusty MLS visitors Thursday night, registering a 5-2 victory in the first leg of the CONCACAF Champions League quarterfinals at Estadio Alejandro Morera Soto in Alajuela. United will need to win 3-0 or 4-1 next Wednesday at RFK Stadium to win the two-game encounter on the away-goal tiebreaker.

United’s fitness and form was not the only problem; goalkeeping was.

Starting in place of injured Bill Hamid, Andrew Dykstra performed poorly as United fell behind by two goals in the opening 22 minutes and 3-1 by halftime.

The deficit was 4-1 in the dying moments when Steve Birnbaum scored on an 89th-minute header, breathing life back into United’s semifinal hopes. But disorganized defending a moment later allowed Jonathan McDonald to score his second goal, restoring Alajuelense’s commanding advantage.

Hamid, a U.S. national team contender, had missed much of preseason recovering from shoulder and back ailments. He returned for a two-game tournament in Texas but then was conspicuously absent from the final tuneup at FC Dallas last Friday. Early this week, Coach Ben Olsen said not to read much into Hamid’s absence. On gameday in Costa Rica, however, United said Hamid was out with an unspecified injury.

Dykstra, who started four league matches last season, was making his first appearance in a serious match since rupturing an Achilles’ tendon last summer.

Alajuelense was also without its first-choice goalkeeper: Peter Pemberton began a six-game suspension for his involvement in a Champions League melee last fall.

His replacement, Dexter Lewis, was a spectator for the first stage of the match as Alajuelense put United under persistent duress. Dykstra made two high-quality saves in the first dozen minutes before unraveling.

In the 14th minute, he arrived late and plowed into Armando Rodriguez at the top corner of the penalty area. Eithel Rodriguez converted the penalty kick in the 15th. Dykstra received a yellow card, creating a perilous situation with only rookie Travis Worra in reserve.

United’s problems continued in the 22nd. Johan Venegas lifted the ball over the backline. Jose Ortiz latched onto it in the clear and snapped a one-timer past Dykstra for a 2-0 lead.

United answered two minutes later, traveling some 90 yards with three touches. It began with Dykstra’s long ball. Chris Pontius flicked it into the box for Espindola, whose running header beat Lewis. The goal not only cut the deficit to one, but provided an away goal — the first tiebreaker in case the total-goals series is level after the second leg.

But the tiebreaker would come into serious play next week only if United were in position to draw even on total goals. Three minutes after Espindola provided a lifeline, Dykstra spilled McDonald’s cross, allowing Venegas to tap the ball into the clear net.

In the wide-open match, United did have several opportunities to trim the deficit. Pontius had the best chance with a point-blank header saved by Lewis.

After halftime, the rampage continued. Ortiz ran at United’s backline and lashed a low, 21-yard effort that beat Dykstra to the near corner for a 4-1 lead in the 54th minute.

Birnbaum got it back with a soaring six-yard header off Espindola’s cross, but United left McDonald unmarked in the box for a simple eight-yard finish.

The outcome of the match had long been settled. And with that final strike, the series was all but over as well.

United notes: Defender-midfielder Markus Halsti, United’s most prominent winter signing, missed the match with a leg injury. Forward Luis Silva, the 2014 co-leading scorer, is not yet ready to return from hamstring rehabilitation. … Comcast SportsNet announced a 24-game TV schedule, eight more matches than required under its contract with the club. The balance of the 34-game schedule will appear on ESPN2, Fox Sports 1 or UniMas. CSN’s first broadcast is the regular season opener March 7 against the Montreal Impact in Washington. Dave Johnson and Santino Quaranta will return as the announcing team.

DCU LIINEUP

Dykstra; Franklin, Boswell, Birnbaum, Kemp; DeLeon, Kitchen, Arnaud (Farfan 81st), Rolfe (Aguilar 71st); Pontius (Arrieta 57th), Espindola.