The Tampa Bay right-hander (8-4), unbeaten in his last 10 starts, struck out 10 to help the Rays (65-56) rebound from a 3-1 defeat to the Red Sox earlier in the day.
"It's just keeping the good roll going," Niemann told reporters.
"Staying confident and going up there and making your pitches. And the defense played great, and the offense has given me some run support."
Tampa Bay's offense enjoyed a three-run eighth inning to pad their slim 3-2 advantage and put away their American League East rivals.
B.J. Upton and Casey Kotchman had RBI singles in the inning, the former finishing 3-for-4 with two runs scored to match the performance of team mate Ben Zobrist.
Jacoby Ellsbury homered in both games for Boston, his sixth-inning blast in the second pulling the Red Sox within 3-2 after the home team fell behind 2-0 early.
However, Boston (74-47) were unable to complete the comeback and their loss dropped them a half-game behind division leaders the New York Yankees (74-46), who defeated Kansas City 9-7.
Erik Bedard (4-8) lost his first game on the mound since joining the Red Sox in a trade last month despite watching the Boston defense record their first triple-play since 1994.
The Red Sox turned the trick in the fourth inning one night after the Milwaukee Brewers accomplished the feat against the Los Angeles Dodgers.
It did not help Bedard much, however, and he allowed three runs in six innings and left trailing 3-2 before Tampa Bay got the best of Boston's bullpen.
"I love the fact that our team loses a very difficult game in the first game and comes back and plays much better in the nightcap," Rays manager Joe Maddon said.
"That's who we are. That's what I appreciate about our players."
The Red Sox played without slugger David Ortiz, who was scratched just before the day's opening game because of a right heel injury.
(Writing by Jahmal Corner in Los Angeles; Editing by John O'Brien)