Harper led off the fourth inning with a slow roller that second baseman Mark Ellis barehanded and flipped to first. The throw appeared to beat Harper and umpire Jeff Gosney called him out.
The 21-year-old Harper kept his head down, screaming his displeasure as he passed Gosney on his way to the third-base dugout. Gosney threw out Harper, who didn't seem to initially realize he'd been ejected.
Nationals manager Matt Williams said he asked third base umpire C.B. Bucknor whether they could wait until the end of the inning before Harper had to leave the dugout. Williams said the crew wanted the All-Star outfielder to go immediately.
''I just didn't want him to be embarrassed by him having to walk in front of everybody down the line,'' Williams said.
The game was briefly delayed while Harper gathered his belongings and walked to the visiting clubhouse beyond the left-field wall.
Fans extended their pens and papers requesting autographs as Harper passed the corner of the left-field bleachers that sit about 10 feet from the foul line.
''We love the way he plays the game because he plays all out and he desperately wants to win so we love that about him,'' Williams said. ''In a situation like that, he has to not take it too far, that's all.''
''The umpire told me that (Harper) said something to him,'' he said. ''The question I had is, `Did he say something?' I didn't see him make a gesture to him or anything, but he said the magic word.''
The Nationals didn't make Harper available for comment.
''I don't know what (Harper) said to him, but as he was walking off the field I said to him, `That was a great at-bat,' because it was,'' Cardinals pitcher Adam Wainwright said.
''He fouled off a bunch of pitches,'' he said. ''He kind of turned away and started walking off, then he looked back and said, `Thanks, by the way.'''
Nationals: Washington has yet to make a decision on its fifth starter. Tanner Roark and Taylor Jordan, the two competitors for the spot, will both pitch in the Nationals' exhibition against Detroit on Sunday in Washington.
Cardinals: Wainwright threw five scoreless innings of one hit ball to cap his spring. The Cardinals' opening day starter allowed four runs in 22 2-3 Grapefruit League innings, striking out 18 while walking one.
''I'm ready for them to start counting,'' he said. ''I feel good. Spring has flown by. I've had a lot of fun down here and now it's time to get going.''
Cardinals: Manager Mike Matheny doesn't expect injured pitchers Jaime Garcia and Jason Motte to make the trip north with the club for the Cardinals' exhibition game at Triple-A Memphis on Friday. Matheny also wasn't sure whether the two pitchers will be part of St. Louis' home-opener festivities.
Nationals: Washington pitcher Doug Fister will start a minor league game on Thursday as he tries to build up his pitch count. He battled elbow inflammation earlier this spring but is scheduled to start the season with the major league club.
Newly signed reliever David Aardsma made his first appearance for St. Louis, allowing one hit and walking one in a scoreless inning of work. The Cardinals have spent much of spring searching for their final bullpen arm and the 32-year-old right-hander likely leaps to the front of a list of candidates that includes Kevin Butler, Scott McGregor and Jorge Rondon.
Aardsma began the spring with Cleveland as a non-roster invitee. He is 23-15 with 69 saves and a 4.23 ERA during a seven-year major league career.
Washington left third baseman Ryan Zimmerman and first baseman Adam LaRoche at their spring training complex so that the pair could get multiple at-bats in minor league games.